Skip to content

Ultra fast and low latency asynchronous socket server & client C# .NET Core library with support TCP, SSL, UDP protocols and 10K connections problem solution

License

Notifications You must be signed in to change notification settings

icemile/NetCoreServer

Repository files navigation

NetCoreServer

Linux build statusOSX build statusWindows build statusNuGet

Ultra fast and low latency asynchronous socket server & client C# .NET Core library with support TCP, SSL, UDP protocols and 10K connections problem solution.

NetCoreServer documentation
NetCoreServer downloads

Contents

Features

  • Cross platform (Linux, OSX, Windows)
  • Asynchronous communication
  • Supported transport protocols: TCP, SSL, UDP, UDP multicast

Requirements

Optional:

How to build?

Setup repository

git clone https://github.com/chronoxor/NetCoreServer.git cd NetCoreServer

Linux

cd build ./unix.sh

OSX

cd build ./unix.sh

Windows (Visual Studio)

Open and build NetCoreServer.sln or run the build script:

cd build vs.bat

The build script will create "release" directory with zip files:

  • NetCoreServer.zip - C# Server assembly
  • Benchmarks.zip - C# Server benchmarks
  • Examples.zip - C# Server examples

Examples

Example: TCP chat server

Here comes the example of the TCP chat server. It handles multiple TCP client sessions and multicast received message from any session to all ones. Also it is possible to send admin message directly from the server.

usingSystem;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Text;usingNetCoreServer;namespaceTcpChatServer{classChatSession:TcpSession{publicChatSession(TcpServerserver):base(server){}protectedoverridevoidOnConnected(){Console.WriteLine($"Chat TCP session with Id {Id} connected!");// Send invite messagestringmessage="Hello from TCP chat! Please send a message or '!' to disconnect the client!";SendAsync(message);}protectedoverridevoidOnDisconnected(){Console.WriteLine($"Chat TCP session with Id {Id} disconnected!");}protectedoverridevoidOnReceived(byte[]buffer,longoffset,longsize){stringmessage=Encoding.UTF8.GetString(buffer,(int)offset,(int)size);Console.WriteLine("Incoming: "+message);// Multicast message to all connected sessionsServer.Multicast(message);// If the buffer starts with '!' the disconnect the current sessionif(message=="!")Disconnect();}protectedoverridevoidOnError(SocketErrorerror){Console.WriteLine($"Chat TCP session caught an error with code {error}");}}classChatServer:TcpServer{publicChatServer(IPAddressaddress,intport):base(address,port){}protectedoverrideTcpSessionCreateSession(){returnnewChatSession(this);}protectedoverridevoidOnError(SocketErrorerror){Console.WriteLine($"Chat TCP server caught an error with code {error}");}}classProgram{staticvoidMain(string[]args){// TCP server portintport=1111;if(args.Length>0)port=int.Parse(args[0]);Console.WriteLine($"TCP server port: {port}");Console.WriteLine();// Create a new TCP chat servervarserver=newChatServer(IPAddress.Any,port);// Start the serverConsole.Write("Server starting...");server.Start();Console.WriteLine("Done!");Console.WriteLine("Press Enter to stop the server or '!' to restart the server...");// Perform text inputfor(;;){stringline=Console.ReadLine();if(line==string.Empty)break;// Restart the serverif(line=="!"){Console.Write("Server restarting...");server.Restart();Console.WriteLine("Done!");continue;}// Multicast admin message to all sessionsline="(admin) "+line;server.Multicast(line);}// Stop the serverConsole.Write("Server stopping...");server.Stop();Console.WriteLine("Done!");}}}

Example: TCP chat client

Here comes the example of the TCP chat client. It connects to the TCP chat server and allows to send message to it and receive new messages.

usingSystem;usingSystem.Net.Sockets;usingSystem.Text;usingSystem.Threading;usingTcpClient=NetCoreServer.TcpClient;namespaceTcpChatClient{classChatClient:TcpClient{publicChatClient(stringaddress,intport):base(address,port){}publicvoidDisconnectAndStop(){_stop=true;DisconnectAsync();while(IsConnected)Thread.Yield();}protectedoverridevoidOnConnected(){Console.WriteLine($"Chat TCP client connected a new session with Id {Id}");}protectedoverridevoidOnDisconnected(){Console.WriteLine($"Chat TCP client disconnected a session with Id {Id}");// Wait for a while...Thread.Sleep(1000);// Try to connect againif(!_stop)ConnectAsync();}protectedoverridevoidOnReceived(byte[]buffer,longoffset,longsize){Console.WriteLine(Encoding.UTF8.GetString(buffer,(int)offset,(int)size));}protectedoverridevoidOnError(SocketErrorerror){Console.WriteLine($"Chat TCP client caught an error with code {error}");}privatebool_stop;}classProgram{staticvoidMain(string[]args){// TCP server addressstringaddress="127.0.0.1";if(args.Length>0)address=args[0];// TCP server portintport=1111;if(args.Length>1)port=int.Parse(args[1]);Console.WriteLine($"TCP server address: {address}");Console.WriteLine($"TCP server port: {port}");Console.WriteLine();// Create a new TCP chat clientvarclient=newChatClient(address,port);// Connect the clientConsole.Write("Client connecting...");client.ConnectAsync();Console.WriteLine("Done!");Console.WriteLine("Press Enter to stop the client or '!' to reconnect the client...");// Perform text inputfor(;;){stringline=Console.ReadLine();if(line==string.Empty)break;// Disconnect the clientif(line=="!"){Console.Write("Client disconnecting...");client.DisconnectAsync();Console.WriteLine("Done!");continue;}// Send the entered text to the chat serverclient.SendAsync(line);}// Disconnect the clientConsole.Write("Client disconnecting...");client.DisconnectAndStop();Console.WriteLine("Done!");}}}

Example: SSL chat server

Here comes the example of the SSL chat server. It handles multiple SSL client sessions and multicast received message from any session to all ones. Also it is possible to send admin message directly from the server.

This example is very similar to the TCP one except the code that prepares SSL context and handshake handler.

usingSystem;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Security.Authentication;usingSystem.Security.Cryptography.X509Certificates;usingSystem.Text;usingNetCoreServer;namespaceSslChatServer{classChatSession:SslSession{publicChatSession(SslServerserver):base(server){}protectedoverridevoidOnConnected(){Console.WriteLine($"Chat SSL session with Id {Id} connected!");}protectedoverridevoidOnHandshaked(){Console.WriteLine($"Chat SSL session with Id {Id} handshaked!");// Send invite messagestringmessage="Hello from SSL chat! Please send a message or '!' to disconnect the client!";Send(message);}protectedoverridevoidOnDisconnected(){Console.WriteLine($"Chat SSL session with Id {Id} disconnected!");}protectedoverridevoidOnReceived(byte[]buffer,longoffset,longsize){stringmessage=Encoding.UTF8.GetString(buffer,(int)offset,(int)size);Console.WriteLine("Incoming: "+message);// Multicast message to all connected sessionsServer.Multicast(message);// If the buffer starts with '!' the disconnect the current sessionif(message=="!")Disconnect();}protectedoverridevoidOnError(SocketErrorerror){Console.WriteLine($"Chat SSL session caught an error with code {error}");}}classChatServer:SslServer{publicChatServer(SslContextcontext,IPAddressaddress,intport):base(context,address,port){}protectedoverrideSslSessionCreateSession(){returnnewChatSession(this);}protectedoverridevoidOnError(SocketErrorerror){Console.WriteLine($"Chat SSL server caught an error with code {error}");}}classProgram{staticvoidMain(string[]args){// SSL server portintport=2222;if(args.Length>0)port=int.Parse(args[0]);Console.WriteLine($"SSL server port: {port}");Console.WriteLine();// Create and prepare a new SSL server contextvarcontext=newSslContext(SslProtocols.Tls12,newX509Certificate2("server.pfx","qwerty"));// Create a new SSL chat servervarserver=newChatServer(context,IPAddress.Any,port);// Start the serverConsole.Write("Server starting...");server.Start();Console.WriteLine("Done!");Console.WriteLine("Press Enter to stop the server or '!' to restart the server...");// Perform text inputfor(;;){stringline=Console.ReadLine();if(line==string.Empty)break;// Restart the serverif(line=="!"){Console.Write("Server restarting...");server.Restart();Console.WriteLine("Done!");continue;}// Multicast admin message to all sessionsline="(admin) "+line;server.Multicast(line);}// Stop the serverConsole.Write("Server stopping...");server.Stop();Console.WriteLine("Done!");}}}

Example: SSL chat client

Here comes the example of the SSL chat client. It connects to the SSL chat server and allows to send message to it and receive new messages.

This example is very similar to the TCP one except the code that prepares SSL context and handshake handler.

usingSystem;usingSystem.Net.Sockets;usingSystem.Security.Authentication;usingSystem.Security.Cryptography.X509Certificates;usingSystem.Text;usingSystem.Threading;usingNetCoreServer;namespaceSslChatClient{classChatClient:SslClient{publicChatClient(SslContextcontext,stringaddress,intport):base(context,address,port){}publicvoidDisconnectAndStop(){_stop=true;DisconnectAsync();while(IsConnected)Thread.Yield();}protectedoverridevoidOnConnected(){Console.WriteLine($"Chat SSL client connected a new session with Id {Id}");}protectedoverridevoidOnHandshaked(){Console.WriteLine($"Chat SSL client handshaked a new session with Id {Id}");}protectedoverridevoidOnDisconnected(){Console.WriteLine($"Chat SSL client disconnected a session with Id {Id}");// Wait for a while...Thread.Sleep(1000);// Try to connect againif(!_stop)ConnectAsync();}protectedoverridevoidOnReceived(byte[]buffer,longoffset,longsize){Console.WriteLine(Encoding.UTF8.GetString(buffer,(int)offset,(int)size));}protectedoverridevoidOnError(SocketErrorerror){Console.WriteLine($"Chat SSL client caught an error with code {error}");}privatebool_stop;}classProgram{staticvoidMain(string[]args){// SSL server addressstringaddress="127.0.0.1";if(args.Length>0)address=args[0];// SSL server portintport=2222;if(args.Length>1)port=int.Parse(args[1]);Console.WriteLine($"SSL server address: {address}");Console.WriteLine($"SSL server port: {port}");Console.WriteLine();// Create and prepare a new SSL client contextvarcontext=newSslContext(SslProtocols.Tls12,newX509Certificate2("client.pfx","qwerty"),(sender,certificate,chain,sslPolicyErrors)=>true);// Create a new SSL chat clientvarclient=newChatClient(context,address,port);// Connect the clientConsole.Write("Client connecting...");client.ConnectAsync();Console.WriteLine("Done!");Console.WriteLine("Press Enter to stop the client or '!' to reconnect the client...");// Perform text inputfor(;;){stringline=Console.ReadLine();if(line==string.Empty)break;// Disconnect the clientif(line=="!"){Console.Write("Client disconnecting...");client.DisconnectAsync();Console.WriteLine("Done!");continue;}// Send the entered text to the chat serverclient.SendAsync(line);}// Disconnect the clientConsole.Write("Client disconnecting...");client.DisconnectAndStop();Console.WriteLine("Done!");}}}

Example: UDP echo server

Here comes the example of the UDP echo server. It receives a datagram mesage from any UDP client and resend it back without any changes.

usingSystem;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Text;usingNetCoreServer;namespaceUdpEchoServer{classEchoServer:UdpServer{publicEchoServer(IPAddressaddress,intport):base(address,port){}protectedoverridevoidOnStarted(){// Start receive datagramsReceiveAsync();}protectedoverridevoidOnReceived(EndPointendpoint,byte[]buffer,longoffset,longsize){Console.WriteLine("Incoming: "+Encoding.UTF8.GetString(buffer,(int)offset,(int)size));// Echo the message back to the senderSendAsync(endpoint,buffer,0,size);}protectedoverridevoidOnSent(EndPointendpoint,longsent){// Continue receive datagramsReceiveAsync();}protectedoverridevoidOnError(SocketErrorerror){Console.WriteLine($"Echo UDP server caught an error with code {error}");}}classProgram{staticvoidMain(string[]args){// UDP server portintport=3333;if(args.Length>0)port=int.Parse(args[0]);Console.WriteLine($"UDP server port: {port}");Console.WriteLine();// Create a new UDP echo servervarserver=newEchoServer(IPAddress.Any,port);// Start the serverConsole.Write("Server starting...");server.Start();Console.WriteLine("Done!");Console.WriteLine("Press Enter to stop the server or '!' to restart the server...");// Perform text inputfor(;;){stringline=Console.ReadLine();if(line==string.Empty)break;// Restart the serverif(line=="!"){Console.Write("Server restarting...");server.Restart();Console.WriteLine("Done!");}}// Stop the serverConsole.Write("Server stopping...");server.Stop();Console.WriteLine("Done!");}}}

Example: UDP echo client

Here comes the example of the UDP echo client. It sends user datagram message to UDP server and listen for response.

usingSystem;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Text;usingSystem.Threading;namespaceUdpEchoClient{classEchoClient:NetCoreServer.UdpClient{publicEchoClient(stringaddress,intport):base(address,port){}publicvoidDisconnectAndStop(){_stop=true;Disconnect();while(IsConnected)Thread.Yield();}protectedoverridevoidOnConnected(){Console.WriteLine($"Echo UDP client connected a new session with Id {Id}");// Start receive datagramsReceiveAsync();}protectedoverridevoidOnDisconnected(){Console.WriteLine($"Echo UDP client disconnected a session with Id {Id}");// Wait for a while...Thread.Sleep(1000);// Try to connect againif(!_stop)Connect();}protectedoverridevoidOnReceived(EndPointendpoint,byte[]buffer,longoffset,longsize){Console.WriteLine("Incoming: "+Encoding.UTF8.GetString(buffer,(int)offset,(int)size));// Continue receive datagramsReceiveAsync();}protectedoverridevoidOnError(SocketErrorerror){Console.WriteLine($"Echo UDP client caught an error with code {error}");}privatebool_stop;}classProgram{staticvoidMain(string[]args){// UDP server addressstringaddress="127.0.0.1";if(args.Length>0)address=args[0];// UDP server portintport=3333;if(args.Length>1)port=int.Parse(args[1]);Console.WriteLine($"UDP server address: {address}");Console.WriteLine($"UDP server port: {port}");Console.WriteLine();// Create a new TCP chat clientvarclient=newEchoClient(address,port);// Connect the clientConsole.Write("Client connecting...");client.Connect();Console.WriteLine("Done!");Console.WriteLine("Press Enter to stop the client or '!' to reconnect the client...");// Perform text inputfor(;;){stringline=Console.ReadLine();if(line==string.Empty)break;// Disconnect the clientif(line=="!"){Console.Write("Client disconnecting...");client.Disconnect();Console.WriteLine("Done!");continue;}// Send the entered text to the chat serverclient.Send(line);}// Disconnect the clientConsole.Write("Client disconnecting...");client.DisconnectAndStop();Console.WriteLine("Done!");}}}

Example: UDP multicast server

Here comes the example of the UDP multicast server. It use multicast IP address to multicast datagram messages to all client that joined corresponding UDP multicast group.

usingSystem;usingSystem.Net;usingSystem.Net.Sockets;usingNetCoreServer;namespaceUdpMulticastServer{classMulticastServer:UdpServer{publicMulticastServer(IPAddressaddress,intport):base(address,port){}protectedoverridevoidOnError(SocketErrorerror){Console.WriteLine($"Multicast UDP server caught an error with code {error}");}}classProgram{staticvoidMain(string[]args){// UDP multicast addressstringmulticastAddress="239.255.0.1";if(args.Length>0)multicastAddress=args[0];// UDP multicast portintmulticastPort=3334;if(args.Length>1)multicastPort=int.Parse(args[1]);Console.WriteLine($"UDP multicast address: {multicastAddress}");Console.WriteLine($"UDP multicast port: {multicastPort}");Console.WriteLine();// Create a new UDP multicast servervarserver=newMulticastServer(IPAddress.Any,0);// Start the multicast serverConsole.Write("Server starting...");server.Start(multicastAddress,multicastPort);Console.WriteLine("Done!");Console.WriteLine("Press Enter to stop the server or '!' to restart the server...");// Perform text inputfor(;;){stringline=Console.ReadLine();if(line==string.Empty)break;// Restart the serverif(line=="!"){Console.Write("Server restarting...");server.Restart();Console.WriteLine("Done!");continue;}// Multicast admin message to all sessionsline="(admin) "+line;server.Multicast(line);}// Stop the serverConsole.Write("Server stopping...");server.Stop();Console.WriteLine("Done!");}}}

Example: UDP multicast client

Here comes the example of the UDP multicast client. It use multicast IP address and joins UDP multicast group in order to receive multicasted datagram messages from UDP server.

usingSystem;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Text;usingSystem.Threading;namespaceUdpMulticastClient{classMulticastClient:NetCoreServer.UdpClient{publicstringMulticast;publicMulticastClient(stringaddress,intport):base(address,port){}publicvoidDisconnectAndStop(){_stop=true;Disconnect();while(IsConnected)Thread.Yield();}protectedoverridevoidOnConnected(){Console.WriteLine($"Multicast UDP client connected a new session with Id {Id}");// Join UDP multicast groupJoinMulticastGroup(Multicast);// Start receive datagramsReceiveAsync();}protectedoverridevoidOnDisconnected(){Console.WriteLine($"Multicast UDP client disconnected a session with Id {Id}");// Wait for a while...Thread.Sleep(1000);// Try to connect againif(!_stop)Connect();}protectedoverridevoidOnReceived(EndPointendpoint,byte[]buffer,longoffset,longsize){Console.WriteLine("Incoming: "+Encoding.UTF8.GetString(buffer,(int)offset,(int)size));// Continue receive datagramsReceiveAsync();}protectedoverridevoidOnError(SocketErrorerror){Console.WriteLine($"Multicast UDP client caught an error with code {error}");}privatebool_stop;}classProgram{staticvoidMain(string[]args){// UDP listen addressstringlistenAddress="0.0.0.0";if(args.Length>0)listenAddress=args[0];// UDP multicast addressstringmulticastAddress="239.255.0.1";if(args.Length>1)multicastAddress=args[1];// UDP multicast portintmulticastPort=3334;if(args.Length>2)multicastPort=int.Parse(args[2]);Console.WriteLine($"UDP listen address: {listenAddress}");Console.WriteLine($"UDP multicast address: {multicastAddress}");Console.WriteLine($"UDP multicast port: {multicastPort}");Console.WriteLine();// Create a new TCP chat clientvarclient=newMulticastClient(listenAddress,multicastPort);client.SetupMulticast(true);client.Multicast=multicastAddress;// Connect the clientConsole.Write("Client connecting...");client.Connect();Console.WriteLine("Done!");Console.WriteLine("Press Enter to stop the client or '!' to reconnect the client...");// Perform text inputfor(;;){stringline=Console.ReadLine();if(line==string.Empty)break;// Disconnect the clientif(line=="!"){Console.Write("Client disconnecting...");client.Disconnect();Console.WriteLine("Done!");continue;}}// Disconnect the clientConsole.Write("Client disconnecting...");client.DisconnectAndStop();Console.WriteLine("Done!");}}}

Performance

Here comes several communication scenarios with timing measurements.

Benchmark environment is the following:

CPU architecutre: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz CPU logical cores: 8 CPU physical cores: 4 CPU clock speed: 3.998 GHz CPU Hyper-Threading: enabled RAM total: 31.962 GiB RAM free: 21.623 GiB OS version: Microsoft Windows 8 Enterprise Edition (build 9200), 64-bit OS bits: 64-bit Process bits: 64-bit Process configuaraion: release 

Benchmark: Round-Trip

Round-trip

This scenario sends lots of messages from several clients to a server. The server responses to each message and resend the similar response to the client. The benchmark measures total Round-trip time to send all messages and receive all responses, messages & data throughput, count of errors.

TCP echo server

Server address: 127.0.0.1 Server port: 1111 Working clients: 1 Working messages: 1000 Message size: 32 Seconds to benchmarking: 10 Errors: 0 Total time: 10.017 s Total data: 389.962 MiB Total messages: 12777566 Data throughput: 38.948 MiB/s Message latency: 783 ns Message throughput: 1275543 msg/s 
Server address: 127.0.0.1 Server port: 1111 Working clients: 100 Working messages: 1000 Message size: 32 Seconds to benchmarking: 10 Errors: 0 Total time: 10.179 s Total data: 884.520 MiB Total messages: 28983575 Data throughput: 86.911 MiB/s Message latency: 351 ns Message throughput: 2847229 msg/s 

SSL echo server

Server address: 127.0.0.1 Server port: 2222 Working clients: 1 Working messages: 1000 Message size: 32 Seconds to benchmarking: 10 Errors: 0 Total time: 10.088 s Total data: 41.873 MiB Total messages: 1371444 Data throughput: 4.152 MiB/s Message latency: 7.356 mcs Message throughput: 135939 msg/s 
Server address: 127.0.0.1 Server port: 2222 Working clients: 100 Working messages: 1000 Message size: 32 Seconds to benchmarking: 10 Errors: 0 Total time: 12.270 s Total data: 187.644 MiB Total messages: 6148244 Data throughput: 15.298 MiB/s Message latency: 1.995 mcs Message throughput: 501056 msg/s 

UDP echo server

Server address: 127.0.0.1 Server port: 3333 Working clients: 1 Working messages: 1000 Message size: 32 Seconds to benchmarking: 10 Errors: 0 Total time: 10.023 s Total data: 38.614 MiB Total messages: 1264835 Data throughput: 3.871 MiB/s Message latency: 7.924 mcs Message throughput: 126187 msg/s 
Server address: 127.0.0.1 Server port: 3333 Working clients: 100 Working messages: 1000 Message size: 32 Seconds to benchmarking: 10 Errors: 0 Total time: 10.465 s Total data: 32.683 MiB Total messages: 1070523 Data throughput: 3.124 MiB/s Message latency: 9.776 mcs Message throughput: 102287 msg/s 

Benchmark: Multicast

Multicast

In this scenario server multicasts messages to all connected clients. The benchmark counts total messages received by all clients for all the working time and measures messages & data throughput, count of errors.

TCP multicast server

Server address: 127.0.0.1 Server port: 1111 Working clients: 1 Message size: 32 Seconds to benchmarking: 10 Errors: 0 Total time: 10.019 s Total data: 66.374 MiB Total messages: 2174676 Data throughput: 6.638 MiB/s Message latency: 4.607 mcs Message throughput: 217051 msg/s 
Server address: 127.0.0.1 Server port: 1111 Working clients: 100 Message size: 32 Errors: 0 Total time: 10.031 s Total data: 127.428 MiB Total messages: 4175253 Data throughput: 12.718 MiB/s Message latency: 2.402 mcs Message throughput: 416205 msg/s 

SSL multicast server

Server address: 127.0.0.1 Server port: 2222 Working clients: 1 Message size: 32 Seconds to benchmarking: 10 Errors: 0 Total time: 10.091 s Total data: 46.905 MiB Total messages: 1536317 Data throughput: 4.661 MiB/s Message latency: 6.568 mcs Message throughput: 152236 msg/s 
Server address: 127.0.0.1 Server port: 2222 Working clients: 100 Message size: 32 Errors: 0 Total time: 10.278 s Total data: 66.540 MiB Total messages: 2179997 Data throughput: 6.483 MiB/s Message latency: 4.715 mcs Message throughput: 212083 msg/s 

UDP multicast server

Server address: 239.255.0.1 Server port: 3333 Working clients: 1 Message size: 32 Seconds to benchmarking: 10 Errors: 0 Total time: 10.020 s Total data: 15.961 MiB Total messages: 522293 Data throughput: 1.604 MiB/s Message latency: 19.185 mcs Message throughput: 52123 msg/s 
Server address: 239.255.0.1 Server port: 3333 Working clients: 100 Message size: 32 Seconds to benchmarking: 10 Errors: 0 Total time: 10.029 s Total data: 55.614 MiB Total messages: 1821897 Data throughput: 5.556 MiB/s Message latency: 5.504 mcs Message throughput: 181656 msg/s 

OpenSSL certificates

In order to create OpenSSL based server and client you should prepare a set of SSL certificates. Here comes several steps to get a self-signed set of SSL certificates for testing purposes:

Certificate Authority

  • Create CA private key
openssl genrsa -passout pass:qwerty -out ca-secret.key 4096
  • Remove passphrase
openssl rsa -passin pass:qwerty -in ca-secret.key -out ca.key
  • Create CA self-signed certificate
openssl req -new -x509 -days 3650 -subj '/C=BY/ST=Belarus/L=Minsk/O=Example root CA/OU=Example CA unit/CN=example.com' -key ca.key -out ca.crt
  • Convert CA self-signed certificate to PFX
openssl pkcs12 -export -passout pass:qwerty -inkey ca.key -in ca.crt -out ca.pfx
  • Convert CA self-signed certificate to PEM
openssl pkcs12 -passin pass:qwerty -passout pass:qwerty -in ca.pfx -out ca.pem

SSL Server certificate

  • Create private key for the server
openssl genrsa -passout pass:qwerty -out server-secret.key 4096
  • Remove passphrase
openssl rsa -passin pass:qwerty -in server-secret.key -out server.key
  • Create CSR for the server
openssl req -new -subj '/C=BY/ST=Belarus/L=Minsk/O=Example server/OU=Example server unit/CN=server.example.com' -key server.key -out server.csr
  • Create certificate for the server
openssl x509 -req -days 3650 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt
  • Convert the server certificate to PFX
openssl pkcs12 -export -passout pass:qwerty -inkey server.key -in server.crt -out server.pfx
  • Convert the server certificate to PEM
openssl pkcs12 -passin pass:qwerty -passout pass:qwerty -in server.pfx -out server.pem

SSL Client certificate

  • Create private key for the client
openssl genrsa -passout pass:qwerty -out client-secret.key 4096
  • Remove passphrase
openssl rsa -passin pass:qwerty -in client-secret.key -out client.key
  • Create CSR for the client
openssl req -new -subj '/C=BY/ST=Belarus/L=Minsk/O=Example client/OU=Example client unit/CN=client.example.com' -key client.key -out client.csr
  • Create the client certificate
openssl x509 -req -days 3650 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt
  • Convert the client certificate to PFX
openssl pkcs12 -export -passout pass:qwerty -inkey client.key -in client.crt -out client.pfx
  • Convert the client certificate to PEM
openssl pkcs12 -passin pass:qwerty -passout pass:qwerty -in client.pfx -out client.pem

Diffie-Hellman key exchange

  • Create DH parameters
openssl dhparam -out dh4096.pem 4096

About

Ultra fast and low latency asynchronous socket server & client C# .NET Core library with support TCP, SSL, UDP protocols and 10K connections problem solution

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C#100.0%