The code is shown below:
public static void Main(string[] args) { Int32 port = 12028; String server = "127.0.0.1"; TcpClient client = new TcpClient(server, port); NetworkStream stream = client.GetStream(); byte[] message = new byte[ 8 + 17 + extension.Length + 3 + agentID.Length + 3]; int len = 0; //header UInt32[] length = { IntToNetworkOrder(34) }; Buffer.BlockCopy(length, 0, message, len, sizeof(UInt32)); len += sizeof(UInt32); UInt32[] msgTypeID = { IntToNetworkOrder(38) }; Buffer.BlockCopy(msgTypeID, 0, message, len, sizeof(UInt32)); len += sizeof(UInt32); //fix part (17) UInt32[] invokeID = { IntToNetworkOrder(100) }; Buffer.BlockCopy(invokeID, 0, message, len, sizeof(UInt32)); len += sizeof(UInt32); UInt32[] reserved1 = { IntToNetworkOrder(1) }; Buffer.BlockCopy(reserved1, 0, message, len, sizeof(UInt32)); len += sizeof(UInt32); ushort[] agentState = { ShortToNetworkOrder(3) }; Buffer.BlockCopy(agentState, 0, message, len, sizeof(ushort)); len += sizeof(ushort); ushort[] reserved2 = { ShortToNetworkOrder(0) }; Buffer.BlockCopy(reserved2, 0, message, len, sizeof(ushort)); len += sizeof(ushort); ushort[] reserved3 = { ShortToNetworkOrder(0) }; Buffer.BlockCopy(reserved3, 0, message, len, sizeof(ushort)); len += sizeof(ushort); ushort[] eventReasonCode = { ShortToNetworkOrder(32760) }; Buffer.BlockCopy(eventReasonCode, 0, message, len, sizeof(ushort)); len += sizeof(ushort); byte[] forcedFlag = new byte[] { 0 }; Buffer.BlockCopy(forcedFlag, 0, message, len, sizeof(byte)); len += sizeof(byte); //floating part //agent instrument byte[] agentInstrumentID = new byte[] { 6 }; Buffer.BlockCopy(agentInstrumentID, 0, message, len, sizeof(byte)); len += sizeof(byte); byte[] agentInstrumentLen = new byte[] { (byte)(extension.Length + 1) }; Buffer.BlockCopy(agentInstrumentLen, 0, message, len, sizeof(byte)); len += sizeof(byte); byte[] agentInstrumentData = System.Text.Encoding.ASCII.GetBytes(extension); Buffer.BlockCopy(agentInstrumentData, 0, message, len, agentInstrumentData.Length); len += agentInstrumentData.Length; Buffer.BlockCopy(forcedFlag, 0, message, len, sizeof(byte)); len += sizeof(byte); //agent id byte[] agentIdID = new byte[] { 194 }; Buffer.BlockCopy(agentIdID, 0, message, len, sizeof(byte)); len += sizeof(byte); byte[] agentIdLen = new byte[] { (byte)(agentID.Length + 1) }; Buffer.BlockCopy(agentIdLen, 0, message, len, sizeof(byte)); len += sizeof(byte); byte[] agentIdData = System.Text.Encoding.ASCII.GetBytes(agentID); Buffer.BlockCopy(agentIdData, 0, message, len, agentIdData.Length); len += (agentIdData.Length); Buffer.BlockCopy(forcedFlag, 0, message, len, sizeof(byte)); len += sizeof(byte); stream.Write(message, 0, message.Length); stream.Close(); client.Close(); } public static UInt32 IntToNetworkOrder(UInt32 source) { if (BitConverter.IsLittleEndian) { return (uint)(source >> 24) | ((source << 8) & 0x00FF0000) | ((source >> 8) & 0x0000FF00) | (source << 24); } return source; } public static ushort ShortToNetworkOrder(ushort source) { if (BitConverter.IsLittleEndian) { return (ushort)(source >> 8 | source << 8); } return source; }