// Sends data over the network public static void sendData(ProtocolMessageCode code, byte[] data) { byte[] ba = RemoteEndpoint.prepareProtocolMessage(code, data, CoreConfig.protocolVersion, 0); NetDump.Instance.appendSent(tcpClient.Client, ba, ba.Length); try { tcpClient.Client.Send(ba, SocketFlags.None); if (tcpClient.Client.Connected == false) { Logging.error("Failed senddata to client. Reconnecting."); } } catch (Exception e) { Logging.error(String.Format("CLN: Socket exception, attempting to reconnect {0}", e)); } //Console.WriteLine("sendData done"); }
/// <summary> /// Prepares and sends the disconnect message to the specified remote endpoint. /// </summary> /// <param name="endpoint">Remote client.</param> /// <param name="code">Disconnection reason.</param> /// <param name="message">Optional text message for the user of the remote client.</param> /// <param name="data">Optional payload to further explain the disconnection reason.</param> /// <param name="removeAddressEntry">If true, the remote address will be removed from the `PresenceList`.</param> public static void sendBye(Socket socket, ProtocolByeCode code, string message, string data) { using (MemoryStream m2 = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(m2)) { writer.Write((int)code); writer.Write(message); writer.Write(data); #if TRACE_MEMSTREAM_SIZES Logging.info(String.Format("CoreProtocolMessage::sendBye: {0}", m2.Length)); #endif socket.Send(RemoteEndpoint.prepareProtocolMessage(ProtocolMessageCode.bye, m2.ToArray(), CoreConfig.protocolVersion, 0)); IPEndPoint remoteIP = (IPEndPoint)socket.RemoteEndPoint; string address = remoteIP.Address.ToString() + ":" + remoteIP.Port; Logging.info("Sending bye to {0} with message '{1}' and data '{2}'", address, message, data); } } }