Beispiel #1
0
        // a new client is trying to connect
        private void OnClientConnect(IAsyncResult ar)
        {
            Socket clientSocket = null;

            try
            {
                clientSocket = ListenerSocket.EndAccept(ar);
            }
            catch
            {
                Log.Error("Listener socket is closed");
                return;
            }

            var shaker = new HandshakeHandler(Origin, Location);

            // shake hands - and provide a callback for when hands has been shaken
            shaker.Shake(clientSocket, (handshake) =>
            {
                // instantiate the connection and subscribe to the events
                var wsc           = new WebSocketConnection(clientSocket, handshake);
                wsc.OnDisconnect += new EventHandler <DisconnectedEventArgs>(OnClientDisconnect);

                // add the new client to the list
                ConnectedClients.Add(wsc);

                // fire the connected event
                if (OnConnect != null)
                {
                    OnConnect(this, new WebSocketConnectedEventArgs(wsc));
                }

                // start looking for data
                wsc.StartReceiving();
            });

            // listen some more
            ListenForClients();
        }
 public WebSocketConnectedEventArgs(WebSocketConnection connection)
 {
     Connection = connection;
 }