Facebook
From Baby Tern, 6 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 259
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Sockets;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8.  
  9. namespace Sieci_GG.Utility
  10. {
  11.     class CommunicateServer
  12.     {
  13.         private const string _ipAddress = "192.168.56.101";
  14.         private const int _port = 9004;
  15.         private TcpClient _client;
  16.         private NetworkStream _networkStream;
  17.  
  18.         public void ConnectServer()
  19.         {
  20.             _client = new TcpClient(_ipAddress, _port);
  21.             _networkStream = _client.GetStream();
  22.             Thread newThread = new Thread(Test);
  23.             newThread.Start();
  24.         }
  25.  
  26.         public void Test()
  27.         {
  28.             while (true)
  29.             {
  30.                 _networkStream = _client.GetStream();
  31.                 int buffSize = 0;
  32.                 byte[] inStream = new byte[_client.ReceiveBufferSize];
  33.                 buffSize = _client.ReceiveBufferSize;
  34.                 int test = _networkStream.Read(inStream, 0, buffSize);
  35.                 string returndata = System.Text.Encoding.ASCII.GetString(inStream);
  36.                 ShowDialog.ShowInformation("ss");
  37.                 Thread.Sleep(500);
  38.  
  39.             }
  40.  
  41.         }
  42.  
  43.      
  44.         public void Disconnect()
  45.         {
  46.             _client.Close();
  47.         }
  48.  
  49.  
  50.  
  51.     }
  52. }
  53.