public void Send(Packets.GenericPacket Output) { try { if (ConnectionContext == ConnectionContexts.Connectionless) { return; } if (Client.IsDisconnecting()) { return; } if (Client.IsDisconnected()) { return; } // Begin sending the data to the remote device. SocketSendObject SendOp = new SocketSendObject(); SendOp.outpacket = Output; Socket.BeginSend(Output.GetRawBytes(), 0, (int)Output.Size + 4, SocketFlags.None, new AsyncCallback(SendCallback), SendOp); } catch (SocketException e) { Client.Disconnect("Remote client forcibly closed the connection."); return; } catch (Exception e) { Debug.WriteLine(e.ToString()); } }
private static void Send(ClientContext context, Packets.GenericPacket OutPacket) { // Convert the string data to byte data using ASCII encoding. byte[] byteData = OutPacket.GetRawBytes(); // Begin sending the data to the remote device. context.Stream.BeginWrite(byteData, 0, byteData.Length, new AsyncCallback(SendCallback), context.Client); }