T
TN
Hi, I'm trying to get the IP address of a sender (which is the local
computer currently).
I'm using UDP multicast, with each socket bound to the multicast address
and using ReUseAddress option.
When I do a multicast send using SendTo, and BeginReceive / EndReceive,
it works just fine. However, I would like to obtain the IP address of
the sender so I can respond directly.
I tried using the following code:
private void ReceiveMessage(IAsyncResult iar)
{
Socket remote = (Socket)iar.AsyncState;
IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0);
EndPoint epp = (EndPoint)ep;
int recv = remote.EndReceiveFrom(iar, ref epp);
}
The EndReceiveFrom throws this Exception:
System.NullReferenceException occurred
Message="Object reference not set to an instance of an object."
Source="System"
StackTrace:
at
System.Net.Sockets.OverlappedAsyncResult.GetSocketAddressSizePtr()
at System.Net.Sockets.Socket.EndReceiveFrom(IAsyncResult
asyncResult, EndPoint& endPoint)
at Node.ReceiveMessage(IAsyncResult iar) in
Can anyone help?
Also, I want to debug this to find out what is null, is there any way I
can step into the MSIL code in order to find this out? Thanks
computer currently).
I'm using UDP multicast, with each socket bound to the multicast address
and using ReUseAddress option.
When I do a multicast send using SendTo, and BeginReceive / EndReceive,
it works just fine. However, I would like to obtain the IP address of
the sender so I can respond directly.
I tried using the following code:
private void ReceiveMessage(IAsyncResult iar)
{
Socket remote = (Socket)iar.AsyncState;
IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0);
EndPoint epp = (EndPoint)ep;
int recv = remote.EndReceiveFrom(iar, ref epp);
}
The EndReceiveFrom throws this Exception:
System.NullReferenceException occurred
Message="Object reference not set to an instance of an object."
Source="System"
StackTrace:
at
System.Net.Sockets.OverlappedAsyncResult.GetSocketAddressSizePtr()
at System.Net.Sockets.Socket.EndReceiveFrom(IAsyncResult
asyncResult, EndPoint& endPoint)
at Node.ReceiveMessage(IAsyncResult iar) in
Can anyone help?
Also, I want to debug this to find out what is null, is there any way I
can step into the MSIL code in order to find this out? Thanks