public static void Main(string[] args) { Cfg.Init(); Task.Factory.StartNew(Call); var port = Cfg.GetCfg <int>("Port"); CreateWebHostBuilder(args).UseUrls("http://*:" + port + "/").Build().Run(); }
public async Task StartReceive() { var pkgsize = Cfg.GetCfg <int>("PackageSize"); var buffer = new byte[1024 * pkgsize]; OnOnConnect(new DataEventArgs <string, SocketClient>(SessionId, this)); var result = await Socket.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None); while (!result.CloseStatus.HasValue) { if (result.MessageType == WebSocketMessageType.Text) { var msg = Encoding.UTF8.GetString(buffer, 0, result.Count); OnOnReceive(new DataEventArgs <string, SocketClient>(msg, this)); } result = await Socket.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None); } await Socket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None); OnOnClose(new DataEventArgs <string, SocketClient>(SessionId, this)); }