Exemple #1
0
        public void Run()
        {

            var server = new WebSocketServer("ws://0.0.0.0:4739");
            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    Console.WriteLine("Open!");
                    var messages = new Subject<object>();
                    messages.Subscribe(s => socket.Send(JsonConvert.SerializeObject(s)));
                    var handler = new Handler(messages);
                    _map.Add(socket, handler);
                };
                socket.OnClose = () => Console.WriteLine("Close!");
                socket.OnMessage = s => OnMessage(s, socket);
            });
        }
Exemple #2
0
        public void Run()
        {

            var server = new WebSocketServer("ws://0.0.0.0:4739");
            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    Console.WriteLine("Open!");
                    var state = new ConnectionState();
                    state.Links.Subscribe(s => socket.Send(JsonConvert.SerializeObject(CreateLinkMessage(s))));
                    state.Status.Subscribe(s => socket.Send(JsonConvert.SerializeObject(CreateStatusMessage(s))));
                    var handler = new Handler(new DuckDuckGoClient());
                    handler.OnConnectionOpen(state.GoClicks, state.QueryInputs, state.InstantSearchChanges, state.EnterPresses, state.Links, state.Status);
                    stateBySocket.Add(socket, state);
                };
                socket.OnClose = () => Console.WriteLine("Close!");
                socket.OnMessage = s => OnMessage(s, socket);
            });
        }