public void StartReceiving() { should_receive = true; Thread x = new Thread(Receive); x.Start(); connectionChanged.Invoke(true); }
public bool Disconnect() { if (client != null && client.Connected) { stream.Flush(); stream.Close(); } ConnectionStatusChnaged.Invoke(false); return(true); }
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(); } }