Team XSockets.NET

Use your certificates in XSockets

This sample only shows how to connect the C# client to the server with the cert.

  1. Create 2 console applications, one for the server and one for the client.
  2. Install XSockets into the server console, and XSockets.Client into the client console.

Server Configuration

We load the certificate, we have to do it from the file since we did not install the certificate into the LocalMachine.

using System.Security.Cryptography.X509Certificates;
using XSockets.Core.Configuration;

namespace MySecurity
{
    public class MySecureConfig : ConfigurationSetting
    {
        public MySecureConfig() : base("wss://192.168.1.7:4503")
        {            
            this.Certificate = new X509Certificate2("c:\\temp\\SSL\\ServerCert.pfx","Test123");            
        }
    }
}

Note: You can also load the cert in the constructor by setting CertificateLocation and DistinguishedName.

CertificateLocation = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
CertificateSubjectDistinguishedName = "cn=localhost";

Start Server

Just in case you do not know how to start the server in a console application.

using System;
using XSockets.Core.Common.Socket;

namespace MySecurity
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var container = XSockets.Plugin.Framework.Composable.GetExport<IXSocketServerContainer>())
            {
                container.Start();
                Console.ReadLine();
            }
        }
    }
}

Connect the client console

Just connecting and printing out some messages.

using System;
using System.Security.Cryptography.X509Certificates;
using XSockets.Client40;

namespace MyClient
{
    class Program
    {
        static void Main(string[] args)
        {
            var c = new XSocketClient("wss://192.168.1.7:4503", "http://localhost", "generic");
            c.AddClientCertificate(new X509Certificate2("c:\\temp\\SSL\\ClientCert.pfx","Test123"));
            c.OnConnected += (sender, eventArgs) => Console.WriteLine("Connected");
            c.Controller("generic").OnOpen += (sender, connectArgs) => Console.WriteLine("Generic Open");

            c.Open();

            Console.ReadLine();
        }
    }
}

results matching ""

    No results matching ""