L
Logan McKinley
I have a client server application where the client sends mouse movements
and text to the server like "MVU 15" would move the mouse up 15 pixels and
"CHAR a" would send an 'a' to the current application. The problem I am
having is that when I try to send a string of chars I get multiple sends
when I read from the TCP/IP stream for instance on one read I might get
"CHAR aCH" then the next read I will get "AR bCH" which obviously breaks my
code.
I am using the following code to send the data
---------------------------
System.IO.StreamWriter NStream;
client = new System.Net.Sockets.TcpClient();
client.Connect(System.Net.IPAddress.Parse(strIPAddress),6254);
NStream = new System.IO.StreamWriter(client.GetStream());
NStream.Write(s);
NStream.Flush();
---------------------------
and the following to read the data
---------------------------
skt = listener.AcceptSocket();
byte[] b = new byte[15];
res = skt.Receive(b);
----------------------------------------
I was thinking i will pad the data to 15 chars but it doesn't seem to be a
problem for most things, but that might have been a result of the speed it
was sent.
Any ideas would be great.
Thanks in advance,
~Logan
and text to the server like "MVU 15" would move the mouse up 15 pixels and
"CHAR a" would send an 'a' to the current application. The problem I am
having is that when I try to send a string of chars I get multiple sends
when I read from the TCP/IP stream for instance on one read I might get
"CHAR aCH" then the next read I will get "AR bCH" which obviously breaks my
code.
I am using the following code to send the data
---------------------------
System.IO.StreamWriter NStream;
client = new System.Net.Sockets.TcpClient();
client.Connect(System.Net.IPAddress.Parse(strIPAddress),6254);
NStream = new System.IO.StreamWriter(client.GetStream());
NStream.Write(s);
NStream.Flush();
---------------------------
and the following to read the data
---------------------------
skt = listener.AcceptSocket();
byte[] b = new byte[15];
res = skt.Receive(b);
----------------------------------------
I was thinking i will pad the data to 15 chars but it doesn't seem to be a
problem for most things, but that might have been a result of the speed it
was sent.
Any ideas would be great.
Thanks in advance,
~Logan