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

The Socket class represents a network connection and is modelled after the Posix socket functions. It can either listen for connections, represent one end of an established connection or simply send and receive datagrams. The socket has an address family, socket type and protocol type.It is almost always better to use wrappers like DatagramConduit?, MulticastConduit?, SocketConduit? and ServerSocket?, as those suit Tango's IO model and are easier to use.

Address families

Address families are implemented by layer 3 of the OSI model.

AF_INETIPv4: The internet protocol, version 4. An IPv4 address is 32 bits long, and typically looks like IPv4 addresses are the most commonly used ones.
AF_INET6IPv6: The internet protocol, version 6. IPv6 addresses are 128 bits long, and look like 2001:19f0:feee::dead:beef:cafe. Although not in widespread use yet, IPv6 should be considered, as it may replace IPv4 over time.
AF_UNIXUnix sockets. (?)

Socket types and protocol types

Socket typeProtocol type
STREAM: A reliable stream of data. Lost or damaged packets will be retransmitted, duplicates ignored and most errors will be detected. Data is guaranteed to arrive in the right order. Data is however not guaranteed to arrive in the same chunks as it was written: The string "abcd" may be received as "abcd", "ab" followed by "cd" or even "a", "b", "c" and "d". Also, latency can be too high for some applications.TCP: The most often used stream protocol. HTTP, SSH, IRC, FTP and X11 are only a few applications of TCP.
DGRAM: An unreliable sequence of packets. Packets may arrive, arrive out of order, arrive twice or not arrive at all. This will go unnoticed by the operating system, so the application has to take care of that. If they arrive, packets are guaranteed to arrive as they were sent: "abcd" will be received as "abcd", never as "ab" followed by "cd".UDP: The most often used datagram protocol. It is used by DHCP, NTP, TFTP, DNS and various protocols with a focus on low latency, such as RTSP. Unlike TCP, UDP is multicast capable.
RAW: Raw protocol access. (?)(?)
RDM: A sequence of reliably delivered messages.(?)
SEQPACKET: A sequence of reliable datagrams. (Difference to RDM?)(?)