Example #1
0
        public void StartReceiving()
        {
            should_receive = true;
            Thread x = new Thread(Receive);

            x.Start();
            connectionChanged.Invoke(true);
        }
Example #2
0
 public bool Disconnect()
 {
     if (client != null && client.Connected)
     {
         stream.Flush();
         stream.Close();
     }
     ConnectionStatusChnaged.Invoke(false);
     return(true);
 }
Example #3
0
 private void Send_msg(byte[] data, byte TYPE)
 {
     try
     {
         if (stream.CanWrite)
         {
             byte[] l      = BitConverter.GetBytes(data.Length + 1);
             byte[] header = new byte[5];
             Buffer.BlockCopy(l, 0, header, 0, 4);
             header[4] = TYPE;
             stream.Write(header, 0, 5);
             stream.Write(data, 0, data.Length);
         }
         else
         {
             //throw new System.InvalidOperationException("cant write to socket");
         }
     }
     catch (System.IO.IOException)
     {
         ConnectionStatusChnaged.Invoke(false);
         stream.Close();
     }
 }