ID:1681104
 
Hi,

I've been trying to make a remote application which would operate by sending Topic messages to the server via sockets, however I've failed at trying to send the correct message. Any help will be appreciated.

Php:

return "\x00\x83" . pack( 'n', strlen( $query_string) + 6 ) . "\x00\x00\x00\x00\x00" . $query_string . "\x00";
The title says C# topic message so I'm going to assume you're trying to send topic messages via C# and not php.

The php you posted is the correct format, if you're having trouble creating that in C# you can use the below code:

        private byte[] topic(string str)
{
if (str[0] != '?') str = "?" + str;

byte[] bytes = Encoding.ASCII.GetBytes(str);
byte[] bytes2send = new byte[bytes.Length + 10];

bytes2send[1] = 0x83;
packn(bytes.Length + 6).CopyTo(bytes2send, 2);

bytes.CopyTo(bytes2send, 9);

return bytes2send;
}

private byte[] packn(int num)
{
byte[] packed = BitConverter.GetBytes((short)num);
if (BitConverter.IsLittleEndian)
{
Array.Reverse(packed);
}
return packed;
}


topic() will build you a byte array you can send via a tcp socket.
Wow, thank you so much for this, I've been trying to get it to work for a few days :D