示例#1
0
        //runs the join loop for the client
        private void clientJoinLoop()
        {
            while (!received.Equals("Started"))
            {
                bytesRead = clientStream.Read(receiveBuf, 0, messageSize);
                received  = encoder.GetString(receiveBuf, 0, bytesRead);
                Console.WriteLine(received);
                Thread.Sleep(10);

                if (received.Equals("Started"))
                {
                    break;
                }
                if (int.Parse(received) != players)
                {
                    commBuffer.addReceive(received);
                    players = int.Parse(received);
                }


                if (!commBuffer.sendEmpty())
                {
                    send = commBuffer.fromSend();
                }
                else
                {
                    send = "waiting";
                }
                Console.WriteLine("sending " + send);
                sendBuf = encoder.GetBytes(send);
                clientStream.Write(sendBuf, 0, sendBuf.Length);
            }
        }