예제 #1
0
        public void Client()
        {
            String message = "";

            try
            {
                NetworkStream = TcpClient.GetStream();
                StreamReader  = new StreamReader(NetworkStream);
                StreamWriter  = new StreamWriter(NetworkStream);

                int  i;
                bool quit = false;

                while (!quit)
                {
                }
            }
            catch (IOException ioe)
            { }
            finally
            {
                TcpClient.Close(); // Shutdown and end connection
                ThreadClient.IsBackground = true;
                ThreadClient.Abort();
            }
        }
예제 #2
0
 public void Client()
 {
     try
     {
         NetworkStream = TcpClient.GetStream();
         StreamReader  = new StreamReader(NetworkStream);
         StreamWriter  = new StreamWriter(NetworkStream);
         while (!quit)
         {
             ;
         }
     }
     catch (IOException ioe)
     {
         Console.WriteLine(ioe);
     }
     finally
     {
         TcpClient.Close(); // Shutdown and end connection
         ThreadClient.IsBackground = true;
         ThreadClient.Abort();
     }
 }
        /// <summary>
        /// Listens for messages from a client
        /// </summary>
        public void ClientThread()
        {
            string msg = "";

            try
            {
                NetworkStream = Client.GetStream();
                StreamReader  = new StreamReader(NetworkStream);
                StreamWriter  = new StreamWriter(NetworkStream);

                ContestInfo info = contestPresenter.CurrentContest.Info;
                msg = "contest:" + info.Name + "|" + info.City + "|" + info.Arena;
                // contest: Example Event|Lyon|Arena

                StreamWriter.WriteLine(msg);
                StreamWriter.Flush();

                while (true)
                {
                    // read what the client has to say
                    msg = StreamReader.ReadLine();

                    if (msg == null || msg.StartsWith("quit"))
                    {
                        break;
                    }
                    else if (msg.StartsWith("Login:"******"denied");
                            StreamWriter.Flush();
                        }
                    }
                    else if (msg.StartsWith("Points:"))
                    {
                        Points = msg.Substring(7);
                        AddPointToList(Points.ToString());
                    }
                }
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
            }
            finally
            {
                if (!IsHost)
                {
                    Client.Close();

                    foreach (var client in Server.ClientList)
                    {
                        if (this == client)
                        {
                            Server.ClientList.Remove(client);
                            break;
                        }
                    }
                    Server.UpdateJudgeListView();
                    ThreadClient.Abort();
                }
            }
        }