Ejemplo n.º 1
0
        public void Awake()
        {
            instance = this;

            if (serverIp == null)
            { // Server: start listening for connections
                this.isServer = true;
                listener      = new TcpListener(listen_ip: IPAddress.Any, port: Globals.port);
                listener.Start();
                listener.BeginAcceptTcpClient(OnServerConnect, null);
            }
            else
            { // Client: try connecting to the server
                TcpClient          client          = new TcpClient();
                TcpConnectedClient connectedClient = new TcpConnectedClient(client);
                clientList.Add(connectedClient);
                client.BeginConnect(serverIp, Globals.port, (ar) => connectedClient.EndConnect(ar), null);
            }
        }
Ejemplo n.º 2
0
        public void Awake()
        {
            instance = this;

            if (serverIp == null)
            { // Server: start listening for connections
                Console.WriteLine("Starting Server...");
                isServer = true;
                listener = new TcpListener(localaddr: IPAddress.Any, port: Globals.Port);
                listener.Start();
                listener.BeginAcceptTcpClient(OnServerConnect, null);
            }
            else
            { // Client: try connecting to the server
                Console.WriteLine("Trying to connect to Server...");
                TcpClient          client          = new TcpClient();
                TcpConnectedClient connectedClient = new TcpConnectedClient(client);
                clientList.Add(connectedClient);
                client.BeginConnect(serverIp, Globals.Port, (ar) => connectedClient.EndConnect(ar), null);
            }
        }