Exemplo n.º 1
0
        /// <summary>
        /// This method is called each time a new client is connected.
        /// </summary>
        /// <param name="pClientSocket">The client socket.</param>
        /// <param name="pError">The error during connection.</param>
        /// <returns></returns>
        private Socket NewClient(ISocket pClientSocket, Exception pError)
        {
            if (pClientSocket?.GetSocket() != null)
            {
                AweSock.TcpAccept(this.ListenSocket, SocketCommunicationTypes.NonBlocking, this.NewClient);
                ClientView lClientView = new ClientView()
                {
                    Socket = pClientSocket
                };
                this.Clients.TryAdd(lClientView, lClientView);
                this.ClientConnected?.Invoke(this, lClientView, null);
                return(pClientSocket.GetSocket());
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Decodes the specified received buffer.
        /// </summary>
        /// <param name="pReceivedBuffer">The p received buffer.</param>
        /// <param name="pClient">The client.</param>
        internal void Decode(string pReceivedBuffer, ClientView pClient)
        {
            IEnumerable <ANetworkCommand> lCommands = this.CommandInterpreter.Parse(pReceivedBuffer).Cast <ANetworkCommand>();

            foreach (var lCommand in lCommands)
            {
                lCommand.ClientView = pClient;
                if (lCommand is DeclareClient)
                {
                    lCommand.Execute(this);
                }
                lCommand.ClientId = lCommand.ClientView.Id;
                this.CommandReceived?.Invoke(this, lCommand);
                Console.WriteLine("[" + lCommand.ClientId + "] = " + lCommand.Encode());
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Notifies the client declared.
 /// </summary>
 /// <param name="pClientView">The p client view.</param>
 /// <param name="pPending">A pending client which has been removed because a previous client (in state Lost) already exists .</param>
 internal void NotifyClientDeclared(ClientView pClientView, ClientView pPending)
 {
     this.ClientDeclared?.Invoke(this, pClientView, pPending);
 }
Exemplo n.º 4
0
 /// <summary>
 /// A client is lost.
 /// </summary>
 /// <param name="pClient">The lost client</param>
 internal void LostClient(ClientView pClient)
 {
     pClient.Socket = null;
     pClient.Status = Status.Lost;
     this.ClientLost?.Invoke(this, pClient, null);
 }