public bool SendString(string SendString) { bool bSuccess = false; lock (this) { if (socketStream != null) { try { byte[] SendBytes = Encoding.UTF8.GetBytes(SendString); byte[] bFormFeed = new byte[] { (byte)0x0c }; RSMPGS.Statistics["TxPackets"]++; RSMPGS.Statistics["TxBytes"] += SendBytes.GetLength(0); switch (SocketServer.TcpSocket.WrapMethod) { case cTcpHelper.WrapMethod_None: SendByteArray(SendBytes, 0, SendBytes.GetLength(0), true, false); break; case cTcpHelper.WrapMethod_LengthPrefix: // Determine packet length byte[] PacketLength = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(SendBytes.GetLength(0))); SendByteArray(PacketLength, 0, PacketLength.GetLength(0), true, true); SendByteArray(SendBytes, 0, SendBytes.GetLength(0), false, false); RSMPGS.Statistics["TxBytes"] += PacketLength.GetLength(0); break; case cTcpHelper.WrapMethod_FormFeed: SendByteArray(SendBytes, 0, SendBytes.GetLength(0), true, false); SendByteArray(bFormFeed, 0, 1, false, false); RSMPGS.Statistics["TxBytes"] += 1; break; } bSuccess = true; } catch (Exception e) { RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Could not send data: " + e.Message); SocketServer.Disconnect(); } } } return(bSuccess); }
public void Disconnect() { switch (ConnectionMethod) { case ConnectionMethod_SocketServer: TcpSocketServer.Disconnect(); break; case ConnectionMethod_SocketClient: TcpSocketClient.Disconnect(); break; } }