socket.receiveFrom() problem

G

Guest

Hi,

I am changing a program so that it uses a datagram socket object instead of
a UdpClient object. (Is it a good idea to do that ? I heard the socket object
is more robust)

I have a strange problem with the datagram socket. When I invoke the method
"socket.receiveFrom()" I get an exception with the message "An invalid
argument was supplied". I can't see what the problem is.
I though that the remoteEndPoint object is not initialized to the proper
value, or in the proper way, but I am not sure anymore about the source of
the problem.

Here is the code:

//Create a datagram/udp socket.
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);

EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);

socket.ReceiveFrom(VSDpacket, ref remoteEndPoint); //throw an exception with
message "an invalid argument was supplied".


Thanks a lot!

Lionel
 
P

Paul G. Tobey [eMVP]

There are several things wrong, I think. Have you followed the directions
in the help for binding the socket to a local endpoint before trying to
receive? What is the declaration and how is VSDpacket constructed? The
sample code in the help description of the version of the ReceiveFrom method
you are using is pretty good...

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top