-
July 12th, 2011, 07:17 PM
#1
UDP/socket Receive issues
trying to setup a connection with a UDP client.
i can connected to it and send to it. Receiving is an issue.
the receive seems to get data as the buffer size is right.
i know this because i check with a packet sniffer but yet, when i convert the buffer it returns nothing. i am sure it has something to do in this area "returnData = Encoding.Default.GetString(recBytes, 0, recBytes.Length);"
udpConn = new UdpClient(HostIP, hostPort);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any,0);
string sendstr = "hello";
Byte[] sendBytes = Encoding.Default.GetBytes(sendstr);
udpConn.Send(sendBytes, sendBytes.Length);
string returnData = "";
Byte[] recBytes = null;
recBytes = udpConn.Receive(ref RemoteIpEndPoint);
returnData += Encoding.Default.GetString(recBytes, 0, recBytes.Length);
txtconsole.AppendText(Environment.NewLine + "returnData " + returnData.Length);
returnData = Encoding.Default.GetString(recBytes, 0, recBytes.Length);
txtconsole.AppendText(Environment.NewLine + "This is the message you received " +
returnData.ToString());
txtconsole.AppendText(Environment.NewLine + "This message was sent from " +
RemoteIpEndPoint.Address.ToString() +
" on their port number " +
RemoteIpEndPoint.Port.ToString());
txtconsole.AppendText(Environment.NewLine + "receiveBytes.Length " +
recBytes.Length.ToString() +
" returnData.Length " +
returnData.Length.ToString());
-
July 12th, 2011, 10:34 PM
#2
Re: UDP/socket Receive issues
So what is being sent and what are you seeing show up in the console window?
Always use [code][/code] tags when posting code.
-
July 12th, 2011, 11:24 PM
#3
Re: UDP/socket Receive issues
console window show nothing. if i break point this line i can see the data in both the "returnData" and recBytes. the raw data has extra \x0 in string.
returnData = Encoding.Default.GetString(recBytes, 0, recBytes.Length);
when i figured that data was there i added a replace ()
returnData = Encoding.Default.GetString(recBytes, 0, recBytes.Length).Replace("\x0",";");
now the string passes to he console window. now it turns into a differnt question
what would be the easyest way to remove all the extra "\x0" bits from the byte before i convert to a string. or is the way i am going it ok?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|