Advertisement
Guest User

Untitled

a guest
May 16th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net.Sockets;
  6. using System.Net;
  7. using System.IO;
  8.  
  9. namespace ConsoleApplication1
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 1024);
  16. try
  17. {
  18. listener.Start(); // rozpoczęcie nasłuchiwania
  19.  
  20.  
  21. }
  22.  
  23. catch (Exception ex)
  24. {
  25. Console.WriteLine(ex.ToString());
  26. Console.Read();
  27. }
  28.  
  29. for (; ; )
  30. {
  31.  
  32.  
  33.  
  34.  
  35.  
  36. try
  37. {
  38.  
  39. bool check = true;
  40. TcpClient newClient = listener.AcceptTcpClient(); // akceptacja
  41. Console.WriteLine("Połączono nowego klienta");
  42.  
  43. while (check)
  44. {
  45. BinaryReader reader = new BinaryReader(newClient.GetStream());
  46. String value = reader.readString();
  47. Console.WriteLine("Klient przesyła:" + value);
  48. if (value == "1")
  49. {
  50. check = false;
  51. }
  52.  
  53. }
  54. newClient.Close();
  55.  
  56. }
  57.  
  58. catch (Exception ex)
  59. {
  60. Console.WriteLine(ex.ToString());
  61. Console.Read();
  62.  
  63. }
  64. }
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement