On Fri, 19 Sep 2008 11:37:30 -0700, TN <ginkeq@yahoo.c omwrote:
Did you call BeginReceiveFro m()? Or BeginReceive()?
If the latter, then that's your problem. You need to call
BeginReceiveFro m() instead. Be sure to note the caveats found in the docs
with respect to initialization of the Socket instance when you intend to
use BeginReceiveFro m().
If that's not your problem, then you need to post a concise-but-complete
code sample. It's extremely difficult to debug another person's code when
you can't actually see it.
By the way, I see that you've followed the code sample in MSDN, including
initializing the EndPoint variable by allocating an IPEndPoint instance
and casting it to EndPoint. It's pointless to cast an IPEndPoint to
EndPoint, as that's a valid implicit conversion anyway (the intermediate
variable was pointless as well).
So the code could look like this:
private void ReceiveMessage( IAsyncResult iar)
{
Socket remote = (Socket)iar.Asy ncState;
EndPoint epp = new IPEndPoint(IPAd dress.Any, 0);
int recv = remote.EndRecei veFrom(iar, ref epp);
}
Pete
[...]
The EndReceiveFrom throws this Exception:
>
System.NullRefe renceException occurred
Message="Object reference not set to an instance of an object."
Source="System"
StackTrace:
at
System.Net.Sock ets.OverlappedA syncResult.GetS ocketAddressSiz ePtr()
at System.Net.Sock ets.Socket.EndR eceiveFrom(IAsy ncResult
asyncResult, EndPoint& endPoint)
at Node.ReceiveMes sage(IAsyncResu lt iar) in
>
Can anyone help?
The EndReceiveFrom throws this Exception:
>
System.NullRefe renceException occurred
Message="Object reference not set to an instance of an object."
Source="System"
StackTrace:
at
System.Net.Sock ets.OverlappedA syncResult.GetS ocketAddressSiz ePtr()
at System.Net.Sock ets.Socket.EndR eceiveFrom(IAsy ncResult
asyncResult, EndPoint& endPoint)
at Node.ReceiveMes sage(IAsyncResu lt iar) in
>
Can anyone help?
If the latter, then that's your problem. You need to call
BeginReceiveFro m() instead. Be sure to note the caveats found in the docs
with respect to initialization of the Socket instance when you intend to
use BeginReceiveFro m().
If that's not your problem, then you need to post a concise-but-complete
code sample. It's extremely difficult to debug another person's code when
you can't actually see it.
By the way, I see that you've followed the code sample in MSDN, including
initializing the EndPoint variable by allocating an IPEndPoint instance
and casting it to EndPoint. It's pointless to cast an IPEndPoint to
EndPoint, as that's a valid implicit conversion anyway (the intermediate
variable was pointless as well).
So the code could look like this:
private void ReceiveMessage( IAsyncResult iar)
{
Socket remote = (Socket)iar.Asy ncState;
EndPoint epp = new IPEndPoint(IPAd dress.Any, 0);
int recv = remote.EndRecei veFrom(iar, ref epp);
}
Pete
Comment