public void StartSecureTest() { //Arrange var objWebSocketServer = Substitute.For <IWebSocketServer>(); var objAction = Substitute.For <Action <IClientConnection> >(); var cert = "MIIGWQIBAzCCBh8GCSqGSIb3DQEHAaCCBhAEggYMMIIGCDCCAwcGCSqGSIb3DQEHBqCCAvgwggL0AgEAMIIC7QYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQICE0sf7/Hp70CAggAgIICwGIm1oPhSvAq0B/YOJYOQjxFOh+T9lu/+fIE7sBID15CtgPHU9jCZBsraoZJXbfTZQVNkONikmCrweF8S89ndZNdWhtyUGfT7Bm9SABLLV5wN6l8PjqEhH8S9cf/y7s75Pkik/T/dGNuij5ouLlUm9yJVvPrrMme1QrXueiBudrI+UixooLgV+O2ITp7wwk+gV85B+mo8aWGQG6cF69Tkj+jsSL6Auqg8sDcrs2UYAOlAqW29MRWgBoilBt6pGvSV0r/EXiNwTGWquRrQDjqovK98ySxUoeWvkf1baFZ8vZFTJuLqbSOyRlWdO3CYb+sM0si9Id0tTis0RxyH/xt7XVKy7Ij3h9gfLR60C7VpUgXho9jhmvD40qMwnC7/2X/7f813fpdVCvRz5EyQiHxOgtov2PAvJF6SiSnJYKSQfvcg6poUBQf0WcgD5crN8xGwrrkb/fLfwaIJ68LFGDxvcFpo4373JM6uFsfWzkaz8JmK7uK8gJdN9jw300JhuGC02pDxpZr5hEF8Mz9l2EYI6UAeCLPyEHI3ZAgas3sjtYvOsn5DS/9wTglhdG2pJ0tO2qo2RGN3vb/yPaGdVmp/6xo5ufohE8TGPlNXpm+TFhNVOZGS6ytBnBQtRiPU2+MSllIYMH0m0AeiVcE7uWPrsmPhSZd8tcRKNKNij7ZJ0n8SU7teoVraXeXKHM0rDAzYF0N1FBIROjzV1x87pqAowuSFySJkSPnceUrfXIJcn4cEsYjF+gaFYEIo2eWJy8XMfCPLbCC9s3BxlkGxHmjhq8FNT52Nu4nQXWp5rvLFSlp74+1pRJzGfqXSyQ2wiKksQNGYzvWZeK5Q/2I4/4I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j+IT2o/ldb+ybhC7vyXmsMDEwITAJBgUrDgMCGgUABBS0PcItuVaWJMyGQ/BkV1yYQwGvSQQIe9JfY1ioo6oCAggA"; var file = Path.GetTempFileName(); File.WriteAllBytes(file, Convert.FromBase64String(cert)); //Act var objServer = new WebsocketServer(objWebSocketServer); objServer.Start(new ServerParams(IPAddress.Parse("127.0.0.1"), 443, file, "") { ConnectionTimeoutSeconds = 666 }, objAction); //Assert objWebSocketServer.Received(1).Start( Arg.Is <IPAddress>(ip => ip.Equals(IPAddress.Parse("127.0.0.1"))), Arg.Is <int>(p => p.Equals(443)), Arg.Is <X509Certificate2>(c => c != null) //could test the raw data? ); Assert.AreEqual(666, objWebSocketServer.ConnectionTimeoutSeconds); }
protected override void CreateRenderGraphs(RenderGraphCollection graphs) { var renderers = GetRenderers(_config); var websocketServer = new WebsocketServer(_serverOptions.Ip, _serverOptions.Port, _serverOptions.Path); websocketServer.SetupGraphs(graphs, renderers); }
protected override void OnClosed(EventArgs e) { // 关闭后保存配置 ConfigurationManager.Save(MainVm.Config); WebsocketServer.Stop(); base.OnClosed(e); }
static void Main(string[] args) { HttpServer s = new HttpServer(8080); WebsocketServer ws = new WebsocketServer(); ws.OnWebsocketConnect += (w) => { w.OnFrame += async(f) => { //send the frame back await f.WebSocket.SendFrame(f.Frame); }; w.Start(); }; s.OnLog += Console.WriteLine; s.Options = HttpServerOptions.GZip | HttpServerOptions.KeepAlive; s.AddRoute("/ws", ws.WebsocketUpgrade); s.AddRoute("/", (h) => Task.Run(() => { var rsp = h.Request.CreateResponse(HttpStatus.OK); rsp.Content = new HttpContent(Encoding.UTF8.GetBytes("<h1>Hello world!</h1>")); rsp.Headers.ContentType = "text/html"; return(rsp); })); s.Start(); Console.ReadKey(); }
protected override void CreateRenderGraphs(RenderGraphCollection graphs, HashSet <string> reportingTags) { var renderers = GetRenderers(_config, reportingTags); var websocketServer = new WebsocketServer(_serverOptions.Ip, _serverOptions.Port, _serverOptions.Path); websocketServer.SetupGraphs(graphs, renderers); reportingTags.Add("Server"); }
public MatchmakerServer(ushort port) { Port = port; _server = new WebsocketServer(Port); _server.NewConnection += OnNewConnection; _server.MessageReceived += OnMessageReceived; }
public XmppServer(ushort port) { Port = port; _server = new WebsocketServer(Port); _server.MessageReceived += OnMessageReceived; _clients = new Dictionary <EndPoint, XmppClient>(); }
public MainWindow() { InitializeComponent(); MainVm = new MainVm { Config = ConfigurationManager.Read() }; DataContext = MainVm; WebsocketServer.Start(MainVm.Config.Port); }
public static void Main(string[] args) { // get the subscription handler ready (tracks websocket clients and their subscriptions) _subscriptionHandler = new SubscriptionHandler(); // get the dataHandler ready (handles incoming blocks and transactions, compares to client subscriptions using the subscription handler) _dataHandler = new DataHandler(_subscriptionHandler); // start with a ZMQ connection for blocks var blockConsumer = new BlockConsumer(_dataHandler.HandleBlock); var zmqBlockClient = new ZMQClient(Config.GetConfigString("ZMQBlockHostname"), Config.GetConfigInt("ZMQBlockPort"), "rawblock", (frameHeader, data, frameCounter) => blockConsumer.EnqueueTask(data, frameCounter)); // start a ZMQ subscription for transactions var transactionConsumer = new TransactionConsumer(_dataHandler.HandleTransaction); var zmqTxClient = new ZMQClient(Config.GetConfigString("ZMQTxHostname"), Config.GetConfigInt("ZMQTxPort"), "rawtx", (frameHeader, data, frameCounter) => transactionConsumer.EnqueueTask(data, frameCounter)); // initialize websocket server // TODO: we need an x509 certificate including key to use secure (wss) - add to application config options _server = new WebsocketServer(IPAddress.Parse(Config.GetConfigString("WebsocketBindIP")), Config.GetConfigInt("WebsocketBindPort"), false, false) // restart websocket listener automatically { RestartAfterListenError = true }; // start the websocket server, and add callbacks to track active sockets _server.Start(socket => { socket.OnOpen = () => { // track the connection _subscriptionHandler.AddSocket(socket); }; socket.OnClose = () => { // stop tracking this connection _subscriptionHandler.RemoveSocket(socket); }; socket.OnMessage = message => { // process incoming message MessageHandler.HandleMessage(socket, message, _subscriptionHandler); }; socket.OnError = exception => { // TODO: handle websocket exceptions }; }); }
public Task UpdateSearchAsync() { InQueueList = Config.BilibiliUsers.Where(m => m.IsInQueue).OrderBy(m => m.QueueNo); if (string.IsNullOrWhiteSpace(SearchKey)) { SearchedList = Config.BilibiliUsers; } else { SearchedList = Config.BilibiliUsers.Where(m => m.UserName.Contains(SearchKey) || m.Uid.ToString().Contains(SearchKey)); } WebsocketServer.Broadcast(JsonConvert.SerializeObject(InQueueList)); return(Task.CompletedTask); }
public void ClientConnectedTest() { //Arrange var objWebSocketServer = Substitute.For <IWebSocketServer>(); var objAction = Substitute.For <Action <IClientConnection> >(); var objEventArgs = Substitute.For <IWebSocketBehavior>(); var objServer = new WebsocketServer(objWebSocketServer); //Act var objParams = new ServerParams(IPAddress.Any, 80); objServer.Start(objParams, objAction); objWebSocketServer.ClientConnected += Raise.Event <EventHandler <IWebSocketBehavior> >(objWebSocketServer, objEventArgs); //Assert objAction.Received(1).Invoke(Arg.Any <IClientConnection>()); }
public void StartInSecureTest() { //Arrange var objWebSocketServer = Substitute.For <IWebSocketServer>(); var objAction = Substitute.For <Action <IClientConnection> >(); //Act var objServer = new WebsocketServer(objWebSocketServer); objServer.Start(new ServerParams(IPAddress.Parse("127.0.0.1"), 80) { ConnectionTimeoutSeconds = 666 }, objAction); //Assert objWebSocketServer.Received(1).Start( Arg.Is <IPAddress>(ip => ip.Equals(IPAddress.Parse("127.0.0.1"))), Arg.Is <int>(p => p.Equals(80)) ); Assert.AreEqual(666, objWebSocketServer.ConnectionTimeoutSeconds); }
public Log(WebsocketServer server) { this.server = server; }
private void Awake() { Instance = this; DontDestroyOnLoad(gameObject); }