Пример #1
0
 internal static void BroadcastChatMessage(string message)
 {
     for (int i = 0; i < instance.clientList.Count; i++)
     {
         TcpConnectedClient client = instance.clientList[i];
         client.Send(message);
     }
 }
Пример #2
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);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
 public void OnDisconnect(TcpConnectedClient client) => clientList.Remove(client);