I am trying to Send data to a socket using GetBytes. The problem is that GetBytes when using a string parameter sends exactly the amount of characters in the string without a null byte. So the listener gets only the amount of data sent - that is if you do this:
UTF8Encoding enc = new UTF8Encoding();
output = "testing";
sock.Send(enc.GetBytes(output),7,0);
This will send 7 bytes and no null byte.
If you do:
UTF8Encoding enc = new UTF8Encoding();
output = "testing";
sock.Send(enc.GetBytes(output));
It will send 7 bytes but the recieving size thinks you send an unknown number of bytes (3349211923). This will overflow the buffer. But this is way all the examples on the net say to do it.
How do you get around this?
Thanks,
Tom
UTF8Encoding enc = new UTF8Encoding();
output = "testing";
sock.Send(enc.GetBytes(output),7,0);
This will send 7 bytes and no null byte.
If you do:
UTF8Encoding enc = new UTF8Encoding();
output = "testing";
sock.Send(enc.GetBytes(output));
It will send 7 bytes but the recieving size thinks you send an unknown number of bytes (3349211923). This will overflow the buffer. But this is way all the examples on the net say to do it.
How do you get around this?
Thanks,
Tom