std.socket
Notes:For Win32 systems, link with ws2_32.lib. Example:
See /dmd/samples/d/listener.d. Authors:
Christopher E. Miller Source:
std/socket.d
- Base exception thrown from a Socket.
- Platform-specific error code.
- The communication domain used to resolve an address.
- Communication semantics
- sequenced, reliable, two-way communication-based byte streams
- connectionless, unreliable datagrams with a fixed maximum length; data may be lost or arrive out of order
- raw protocol access
- reliably-delivered message datagrams
- sequenced, reliable, two-way connection-based datagrams with a fixed maximum length
- Protocol
- internet protocol version 4
- internet control message protocol
- internet group management protocol
- gateway to gateway protocol
- transmission control protocol
- PARC universal packet protocol
- user datagram protocol
- Xerox NS protocol
- internet protocol version 6
- Protocol is a class for retrieving protocol information.
- These members are populated when one of the following functions are called without failure:
- Returns false on failure
- Returns false on failure
- Service is a class for retrieving service information.
- These members are populated when one of the following functions are called without failure:
- If a protocol name is omitted, any protocol will be matched.
Returns:
false on failure.
- Base exception thrown from an InternetHost.
- Platform-specific error code.
- InternetHost is a class for resolving IPv4 addresses.
- These members are populated when one of the following functions are called without failure:
- Resolve host name. Returns false if unable to resolve.
- Resolve IPv4 address number. Returns false if unable to resolve.
- Same as previous, but addr is an IPv4 address string in the dotted-decimal form a.b.c.d. Returns false if unable to resolve.
- Base exception thrown from an Address.
- Address is an abstract class for representing a network addresses.
- Family of this address.
- Human readable string representing this address.
- InternetAddress is a class that represents an IPv4 (internet protocol version
4) address and port.
- Any IPv4 address number.
- An invalid IPv4 address number.
- Any IPv4 port number.
- Overridden to return AddressFamily.INET.
- Returns the IPv4 port number.
- Returns the IPv4 address number.
- this(string addr, ushort port);
- Parameters:
string addr an IPv4 address string in the dotted-decimal form a.b.c.d, or a host name that will be resolved using an InternetHost object. ushort port may be PORT_ANY as stated below. - this(uint addr, ushort port);
this(ushort port); - Construct a new Address. addr may be ADDR_ANY (default) and port may be PORT_ANY, and the actual numbers may not be known until a connection is made.
- Human readable string representing the IPv4 address in dotted-decimal form.
- Human readable string representing the IPv4 port.
- Human readable string representing the IPv4 address and port in the form a.b.c.d:e.
- Parse an IPv4 address string in the dotted-decimal form a.b.c.d and return the number. If the string is not a legitimate IPv4 address, ADDR_NONE is returned.
- How a socket is shutdown:
- socket receives are disallowed
- socket sends are disallowed
- both RECEIVE and SEND
- Flags may be OR'ed together:
- no flags specified
- out-of-band stream data
- peek at incoming data without removing it from the queue, only for receiving
- data should not be subject to routing; this flag may be ignored. Only for sending
- don't send SIGPIPE signal on socket write error and instead return EPIPE
- Duration timeout value.
- A collection of sockets for use with Socket.select.
- this(uint max);
- Set the maximum amount of sockets that may be added.
- this();
- Uses the default maximum for the system.
- Reset the SocketSet so that there are 0 Sockets in the collection.
- Add a Socket to the collection. Adding more than the maximum has dangerous side affects.
- Remove this Socket from the collection.
- Returns nonzero if this Socket is in the collection.
- Return maximum amount of sockets that can be added, like FD_SETSIZE.
- The level at which a socket option is defined:
- socket level
- internet protocol version 4 level
- transmission control protocol level
- user datagram protocol level
- internet protocol version 6 level
- Linger information for use with SocketOption.LINGER.
- Specifies a socket option:
- record debugging information
- allow transmission of broadcast messages
- allow local reuse of address
- linger on close if unsent data is present
- receive out-of-band data in band
- send buffer size
- receive buffer size
- do not route
- disable the Nagle algorithm for send coalescing
- Socket is a class that creates a network communication endpoint using the
Berkeley sockets interface.
- this(AddressFamily af, SocketType type, ProtocolType protocol);
this(AddressFamily af, SocketType type);
this(AddressFamily af, SocketType type, string protocolName); - Create a blocking socket. If a single protocol type exists to support this socket type within the address family, the ProtocolType may be omitted.
- Get underlying socket handle.
- Get/set socket's blocking flag. When a socket is blocking, calls to receive(), accept(), and send() will block and wait for data/action. A non-blocking socket will immediately return instead of blocking.
- Get the socket's address family.
- Property that indicates if this is a valid, alive socket.
- Associate a local address with this socket.
- Establish a connection. If the socket is blocking, connect waits for the connection to be made. If the socket is nonblocking, connect returns immediately and the connection attempt is still in progress.
- Listen for an incoming connection. bind must be called before you can listen. The backlog is a request of how many pending incoming connections are queued until accept'ed.
- Called by accept when a new Socket must be created for a new connection. To use a derived class, override this method and return an instance of your class. The returned Socket's handle must not be set; Socket has a protected constructor this() to use in this situation.
- Accept an incoming connection. If the socket is blocking, accept waits for a connection request. Throws SocketAcceptException if unable to accept. See accepting for use with derived classes.
- Disables sends and/or receives.
- Immediately drop any connections and release socket resources. Calling shutdown before close is recommended for connection-oriented sockets. The Socket object is no longer usable after close.
- Returns the local machine's host name. Idea from mango.
- Remote endpoint Address.
- Local endpoint Address.
- Send or receive error code.
- Send data on the connection. Returns the number of bytes actually sent, or ERROR on failure. If the socket is blocking and there is no buffer space left, send waits.
- Send data to a specific destination Address. If the destination address is not specified, a connection must have been made and that address is used. If the socket is blocking and there is no buffer space left, sendTo waits.
- Receive data on the connection. Returns the number of bytes actually received, 0 if the remote side has closed the connection, or ERROR on failure. If the socket is blocking, receive waits until there is data to be received.
- Receive data and get the remote endpoint Address.
If the socket is blocking, receiveFrom waits until there is data to
be received.
Returns:
the number of bytes actually received, 0 if the remote side has closed the connection, or ERROR on failure. - Get a socket option. Returns the number of bytes written to result.
- Common case of getting integer and boolean options.
- Get the linger option.
- Common case for setting integer and boolean options.
- Set the linger option.
- Wait for a socket to change status. A wait timeout timeval or int microseconds may be specified; if a timeout is not specified or the timeval is null, the maximum timeout is used. The timeval timeout has an unspecified value when select returns. Returns the number of sockets with status changes, 0 on timeout, or -1 on interruption. If the return value is greater than 0, the SocketSets are updated to only contain the sockets having status changes. For a connecting socket, a write status change means the connection is established and it's able to send. For a listening socket, a read status change means there is an incoming connection request and it's able to accept.
- TcpSocket is a shortcut class for a TCP Socket.
- this(AddressFamily family);
- Constructs a blocking TCP Socket.
- this();
- Constructs a blocking TCP Socket.
- this(Address connectTo);
- Constructs a blocking TCP Socket and connects to an InternetAddress.
- UdpSocket is a shortcut class for a UDP Socket.
- this(AddressFamily family);
- Constructs a blocking UDP Socket.
- this();
- Constructs a blocking UDP Socket.