Skip to content

A high performance websocket server library powering Stack Overflow.

License

Notifications You must be signed in to change notification settings

theduffmtl/NetGain

 
 

Repository files navigation

Welcome to StackExchange.NetGain!

NetGain supports:

Build

StackExchange.NetGain is built as a single assembly, StackExchange.NetGain.dll.

NuGet Gallery

StackExchange.NetGain is available on the [NuGet Gallery]

  • [NuGet Gallery: stackexchange.netgain]

You can add StackExchange.NetGain to your project with the NuGet Package Manager, by using the following command in the Package Manager Console.

PM> Install-Package StackExchange.NetGain

WebSocket Server Example

using System;
using System.Net;
using StackExchange.NetGain;
using StackExchange.NetGain.WebSockets;

namespace Example
{
  public class Program
  {
    public static void Main (string[] args)
    {
		IPEndPoint endpoint = new IPEndPoint(IPAddress.Loopback, 6002);
		using(var server = new TcpServer())
		{
			server.ProtocolFactory = WebSocketsSelectorProcessor.Default;
			server.ConnectionTimeoutSeconds = 60;
			server.Received += msg =>
			{
				var conn = (WebSocketConnection)msg.Connection;
				string reply = (string)msg.Value + " / " + conn.Host;
				Console.WriteLine("[server] {0}", msg.Value);
				msg.Connection.Send(msg.Context, reply);
			};
			server.Start("abc", endpoint);
			Console.WriteLine("Server running");

			Console.ReadKey();
		}
		Console.WriteLine("Server dead; press any key");
		Console.ReadKey();
      }
    }
  }
}

About

A high performance websocket server library powering Stack Overflow.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%