Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Leave Comments, Critiques, and Suggestions Here?

Using Sockets: a general introduction to BSD socket programming

General Network Stuff


For various reasons beyond the scope of this document, different types of computers store and send data differently. The gist of it it, do you store/send the big end first, or the little end first. Why all this is important is that network address are always in "Network byte order". Never mind what that is exactly, but for portability sake, never directly set a network port number or IP address. Use either the host &lt-&gt network conversion function or some library facility.

Another gotcha on this is that sending raw data across a network connection only works if the two computers use the same byte order. Don't count on that. Pick a byte order (if one hasn't already been standardized) and convert the data to it from whatever is native to the host system. Similarly on receiving data convert it from the chosen byte order to the host order. This isn't as bad as it may seem, most platforms do this fairly well in hardware and many programming environments have high level constructs to do the conversion automatically. (Tango has high level abstractions to take care of this.)

IP, ports, TCP/UDP


Connected Sockets (TCP)

Connecting to a server

Create a socket


Connect a socket


Accepting sockets as a server

Create a socket


Binding a socket


Listening to a socket


Accepting connections from a socket


Connectionless Sockets (UDP)