Advertisement
Guest User

Untitled

a guest
Aug 21st, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. private void Service()
  2. {
  3.  
  4. while (true)
  5. {
  6. Socket socket = listener.AcceptSocket();
  7.  
  8.  
  9. string newValue = (Environment.NewLine + "Connected:" + socket.RemoteEndPoint);
  10.  
  11. if (richTextBox.InvokeRequired)
  12. {
  13.  
  14. richTextBox.Invoke((MethodInvoker)delegate { richTextBox.AppendText(Environment.NewLine + "Connected:" + socket.RemoteEndPoint); });
  15.  
  16. }
  17.  
  18. else
  19. {
  20.  
  21. richTextBox.AppendText(newValue);
  22.  
  23. }
  24.  
  25. try
  26. {
  27. // Open the stream
  28. Stream stream = new NetworkStream(socket);
  29. StreamReader sr = new StreamReader(stream);
  30. StreamWriter sw = new StreamWriter(stream);
  31. sw.AutoFlush = true;
  32.  
  33. sw.WriteLine("{0} stats available", highScoreTable.Count);
  34. while (true)
  35. {
  36. // Read name from client
  37. string name = sr.ReadLine();
  38. if (name == "" || name == null) break;
  39. richTextBox.AppendText(Environment.NewLine + "User:" + socket.RemoteEndPoint + " command" + name);
  40. // Write score to client
  41. if (highScoreTable.ContainsKey(name))
  42. sw.WriteLine(highScoreTable[name]);
  43.  
  44. else
  45. sw.WriteLine("The command does not exist.");
  46.  
  47.  
  48. }
  49. stream.Close();
  50. }
  51. catch (Exception e)
  52. {
  53. richTextBox.AppendText("");
  54. }
  55. string newValue1 = (Environment.NewLine + "Disconnected:" + socket.RemoteEndPoint);
  56.  
  57. if (richTextBox.InvokeRequired)
  58. {
  59.  
  60. richTextBox.Invoke((MethodInvoker)delegate { richTextBox.AppendText(Environment.NewLine + "Disconnected:" + socket.RemoteEndPoint); });
  61.  
  62. }
  63.  
  64. else
  65. {
  66.  
  67. richTextBox.AppendText(newValue1);
  68.  
  69. }
  70. socket.Close();
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement