NetGain

为 Stack Overflow 提供支持的高性能 websocket 服务器库。「A high performance websocket server library powering Stack Overflow.」

  • 所有者: StackExchange/NetGain
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Welcome to StackExchange.NetGain!

Warning: reduced maintenance

A few things have changed since this library was written:

  • "pipelines" have become the new hotness for high performance low overhead IO code - see my 3-and-a-bit-part series here
  • "Kestrel", combined with pipelines, now provides a great hosting experience for high volume servers
  • HTTP/2 (and above) have reduced the usefulness of web-sockets (one of the main drivers for me and NetGain), since the web-sockets drafts for HTTP/2 never really "took"

As of late 2018, Stack Overflow (Stack Exchange) have migrated away from NetGain, instead using Kestrel's inbuilt web-socket support over HTTP/1.*; it is entirely possible that as we delve more into HTTP/2, we look more in the direction of SSE (EventSource).

So: we're not actively working with, or working on, this library. If you have a burning desire to take it further as an official maintainer (perhaps with some tweaks to naming, obviously) - let me know!


NetGain supports:

  • RFC 6455
  • all draft versions of the RFC (between hixie-76 and v13, aka RFC 6455)
  • hixie-76/hybi-00
  • fixes for various browsers with slightly broken implementations

Build

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

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();
      }
    }
  }
}

主要指標

概覽
名稱與所有者StackExchange/NetGain
主編程語言C#
編程語言C# (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2015-04-24 16:05:02
推送於2019-01-08 09:08:20
最后一次提交2019-01-08 09:08:15
發布數0
用户参与
星數0.9k
關注者數83
派生數143
提交數40
已啟用問題?
問題數19
打開的問題數14
拉請求數2
打開的拉請求數1
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?