Exemplo n.º 1
0
        /// <summary>
        /// Add a new player entry.
        /// </summary>
        private TcpProtocol AddClient(Socket socket)
        {
            TcpProtocol client = new TcpProtocol();

            client.StartReceiving(socket);
            clients.Add(client);
            return(client);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Try to establish a connection with the current tcpEndPoint.
        /// </summary>
        private bool ConnectToTcpEndPoint()
        {
            if (EndPoint != null)
            {
                Status = ConnectionStatus.Connecting;

                try
                {
                    lock (connectingList)
                    {
                        socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        connectingList.Add(socket);
                    }
#if DEBUG
                    Debug.Log("[Client][TcpProtocol:ConnectToTcpEndPoint() -> Connecting to endpoint.");
#endif
                    IAsyncResult result = socket.BeginConnect(EndPoint, OnConnectResult, socket);
                    Thread       th     = new Thread(CancelConnect);
                    th.Start(result);

                    return(true);
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                    Error(ex.Message);
                }
            }
            else
            {
                Debug.LogError(
                    "[Client][TcpProtocol:ConnectToTcpEndPoint()] -> Unable to resolve the specified address.");
                Error("Unable to resolve the specified address");
            }

            return(false);
        }