C# Programming
08-30-2009, 07:51 PM
Hello,
i had a running UDP-Server, but had the problem, that only every second package coming on. So now i wanted to re-code it with Socket and not using the UdpClient.
If i want to receive a datagram with Socket.EndReceiveFrom(ar,ref ep) it doesn't works. I get a NullReferenceException (i think the "ep" is the problem), but if i use Socket.EndReceive(ar) it works well.
Here the code:
string szData;
IPEndPoint ipe = new IPEndPoint(IPAddress.Any, 0);
EndPoint ep = (EndPoint)ipe;
int len = parent.udp_listen.EndReceiveFrom(ar,ref ep);
szData = Encoding.ASCII.GetString(buffer, 0, len);
"parent.udp_listen" is the public UdpClient which is in another class.
So what's wrong... is there another possibility to find out who is the sender of the datagram? Because i need the IP Address and the sending-Port of the sender.
Thanks
i had a running UDP-Server, but had the problem, that only every second package coming on. So now i wanted to re-code it with Socket and not using the UdpClient.
If i want to receive a datagram with Socket.EndReceiveFrom(ar,ref ep) it doesn't works. I get a NullReferenceException (i think the "ep" is the problem), but if i use Socket.EndReceive(ar) it works well.
Here the code:
string szData;
IPEndPoint ipe = new IPEndPoint(IPAddress.Any, 0);
EndPoint ep = (EndPoint)ipe;
int len = parent.udp_listen.EndReceiveFrom(ar,ref ep);
szData = Encoding.ASCII.GetString(buffer, 0, len);
"parent.udp_listen" is the public UdpClient which is in another class.
So what's wrong... is there another possibility to find out who is the sender of the datagram? Because i need the IP Address and the sending-Port of the sender.
Thanks