Listening to UDP sockets
Howard Berkey
howard at well.com
Sat Feb 24 12:07:16 PST 2007
Burton Radons Wrote:
> Burton Radons wrote:
> > I have this code:
> >
> > import std.socket;
> >
> > void main ()
> > {
> > auto address = new InternetAddress (3333);
> > auto socket = new UdpSocket ();
> > socket.bind (address);
> > socket.listen (10);
> > }
> >
> > Which fails during execution on the "listen" line with "Error: Unable to
> > listen on socket". Can anyone help? Replacing "Udp" with "Tcp" lets it
> > work properly so perhaps this is a bug in "std.socket".
>
> I figured it out - I just have to bind (no listen) and then the receive
> buffer must be large enough to contain the entire message or it either
> never returns (since it's waiting for a datagram which is small enough
> to fit, I guess) or returns -1 in nonblocking mode. I knew there were no
> socket connections in the TCP sense but I was expecting sockets to
> simulate it in order to have one unified API.
The D API reflects the traditional sockets API here.
There is a really good guide to sockets programming online at:
http://beej.us/guide/bgnet/
Much of what is in that guide is directly applicable to D network programming.
Howard
More information about the Digitalmars-d-learn
mailing list