private static void SendCallback(IAsyncResult ar) { try { // Retrieve the socket from the state object. Socket handler = (Socket)ar.AsyncState; // Complete sending the data to the remote device. int bytesSent = handler.EndSend(ar); NetUtil.Log("Sent " + bytesSent + " bytes to client."); } catch (Exception e) { NetUtil.Log(e.ToString()); } }
private static void SocketSend(Socket handler, String data, string symkey) { //Encrypt if (symkey != null) { // data = Convert.ToBase64String(TDESHandler.Encrypt(symkey, data)); } NetUtil.Log("About to send: " + data); //Add message ending data += SocketDataBuffer.EOF; // Convert the string data to byte data using UTF8 encoding. byte[] byteData = Encoding.UTF8.GetBytes(data); // Begin sending the data to the remote device. handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler); }