bummper3200
December 31st, 2008, 04:12 PM
I'm currently writing a Server and Client program that communicates over my local network by the TCP Classes. The scenario is Client sends Server a message, Server receives the message, which is encoded in ASCII, decodes it into a string, displays the message in console, then encodes a response to the Client in ASCII, sends it, the client repeats the decode into a string and displays the response to console...
The problem that I am having is that along with the messages that are being transferred are a bunch of control charters (\0 to be exact).
Is there anyway that I can stop this from happening or is there a better way to Encode my messages in to bytes and back to strings than Encoding.ASCII.GetBytes()/.GetString() method?
[EDIT]
I solved the problem with a hackish workaround
string serverResponse = Encoding.ASCII.GetString(bytes);
int index = serverResponse.IndexOf("\0");
serverResponse = serverResponse.Remove(index);
//use response
This just seems a lot of redundant string manipulations(Which I know can have a hefty overhead) so I would like to know if there is a better way to get the same result?
The problem that I am having is that along with the messages that are being transferred are a bunch of control charters (\0 to be exact).
Is there anyway that I can stop this from happening or is there a better way to Encode my messages in to bytes and back to strings than Encoding.ASCII.GetBytes()/.GetString() method?
[EDIT]
I solved the problem with a hackish workaround
string serverResponse = Encoding.ASCII.GetString(bytes);
int index = serverResponse.IndexOf("\0");
serverResponse = serverResponse.Remove(index);
//use response
This just seems a lot of redundant string manipulations(Which I know can have a hefty overhead) so I would like to know if there is a better way to get the same result?