コード例 #1
0
        public String Connect(String ip, int port)
        {
            String clientUUID = "";

            tcpClient = new TcpClient();
            tcpClient.Connect(IPAddress.Parse(ip), port);
            tcpClient.NoDelay = true;
            ConfigureSocket.ConfigureTcpSocket(tcpClient.Client);
            networkStream = tcpClient.GetStream();
            streamReader  = new System.IO.StreamReader(networkStream);
            streamWriter  = new System.IO.StreamWriter(networkStream);
            isConnected   = true;
            while (true)
            {
                String serverData = streamReader.ReadLine();
                if (serverData.StartsWith("connect_ok"))
                {
                    String[] data = serverData.Split('|');
                    clientUUID = data[1];
                    break;
                }
            }

            Debug.WriteLine("CLIENT: Connected to the server at {0}:{1}", ip, port);
            return(clientUUID);
        }
コード例 #2
0
ファイル: GameServer.cs プロジェクト: guidefreitas/SpaceMate
        public void Start()
        {
            tcpListener.Start();
            Program.serverScreen.ShowMessage(String.Format("SERVER: Server started at {0}:{1}", serverIp, serverPort));

            while (true)
            {
                if (tcpListener.Pending())
                {
                    Socket socket = tcpListener.AcceptSocket();
                    ConfigureSocket.ConfigureTcpSocket(socket);
                    Program.serverScreen.ShowMessage("SERVER: Client connected");
                    var task = Task.Run((() => Listeners(socket)));
                }
            }
        }