Пример #1
0
        public SSPClient ProcessClient(SSPServer Server, Socket TcpServer, IAsyncResult result)
        {
            try
            {
                Socket    AcceptSocket = TcpServer.EndAccept(result); //<- can throw a error
                SSPClient client       = Server.GetNewClient();
                client.Handle = AcceptSocket;

                if (AcceptSocket.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    client.RemoteIp = ((IPEndPoint)AcceptSocket.RemoteEndPoint).Address.ToString();
                }
                else
                {
                    client.RemoteIp = AcceptSocket.RemoteEndPoint.ToString().Split(':')[0];
                }


                client.Server     = Server;
                client.Connection = new Network.Connection(client);
                client.ClientId   = Server.randomDecimal.NextDecimal();

                client.serverHS = new ServerMaze(Server.serverProperties.Handshake_Maze_Size, Server.serverProperties.Handshake_MazeCount, Server.serverProperties.Handshake_StepSize);
                client.serverHS.onFindKeyInDatabase += Server.serverHS_onFindKeyInDatabase;

                SysLogger.Log("Accepted peer " + client.RemoteIp, SysLogType.Debug);

                lock (Server.Clients)
                {
                    while (Server.Clients.ContainsKey(client.ClientId))
                    {
                        client.ClientId = Server.randomDecimal.NextDecimal();
                    }
                    Server.Clients.Add(client.ClientId, client);
                }

                try
                {
                    client.onBeforeConnect();
                }
                catch (Exception ex)
                {
                    SysLogger.Log(ex.Message, SysLogType.Error);
                    client.onException(ex, ErrorType.UserLand);
                }

                client.Connection.StartReceiver();
                return(client);
            }
            catch (Exception ex)
            {
                SysLogger.Log(ex.Message, SysLogType.Error);
                return(null);
            }
        }
        public SSPClient ProcessClient(SSPServer Server, Socket TcpServer, IAsyncResult result)
        {
            try
            {
                Socket AcceptSocket = TcpServer.EndAccept(result); //<- can throw a error
                SSPClient client = Server.GetNewClient();
                client.Handle = AcceptSocket;

                if (AcceptSocket.AddressFamily == AddressFamily.InterNetworkV6)
                    client.RemoteIp = ((IPEndPoint)AcceptSocket.RemoteEndPoint).Address.ToString();
                else
                    client.RemoteIp = AcceptSocket.RemoteEndPoint.ToString().Split(':')[0];

                client.Server = Server;
                client.Connection = new Network.Connection(client);
                client.ClientId = Server.randomDecimal.NextDecimal();

                client.serverHS = new ServerMaze(Server.serverProperties.Handshake_Maze_Size, Server.serverProperties.Handshake_MazeCount, Server.serverProperties.Handshake_StepSize);
                client.serverHS.onFindKeyInDatabase += Server.serverHS_onFindKeyInDatabase;

                SysLogger.Log("Accepted peer " + client.RemoteIp, SysLogType.Debug);

                lock (Server.Clients)
                {
                    while (Server.Clients.ContainsKey(client.ClientId))
                        client.ClientId = Server.randomDecimal.NextDecimal();
                    Server.Clients.Add(client.ClientId, client);
                }

                try
                {
                    client.onBeforeConnect();
                }
                catch (Exception ex)
                {
                    SysLogger.Log(ex.Message, SysLogType.Error);
                    client.onException(ex, ErrorType.UserLand);
                }

                client.Connection.StartReceiver();
                return client;
            }
            catch (Exception ex)
            {
                SysLogger.Log(ex.Message, SysLogType.Error);
                return null;
            }
        }