View source code
							
							
						
								Display the source code in std/socket.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								Improve this page
							
							
					
								Quickly fork, edit online, and submit a pull request for this page.
								Requires a signed-in GitHub account. This works well for small changes.
								If you'd like to make larger changes you may want to consider using
								local clone.
							
						Class std.socket.Socket
Socket is a class that creates a network communication endpoint using
 the Berkeley sockets interface.
						
				class Socket
				;
						
					
				Constructors
| Name | Description | 
|---|---|
| this(af, type, protocol) | Create a blocking socket. If a single protocol type exists to support
 this socket type within the address family, the ProtocolTypemay be
 omitted. | 
| this(info) | Create a blocking socket using the parameters from the specified AddressInfostructure. | 
| this(sock, af) | Use an existing socket handle. | 
Properties
| Name | Type | Description | 
|---|---|---|
| addressFamily[get] | AddressFamily | Get the socket's address family. | 
| blocking[get, set] | bool | Get/set socket's blocking flag. | 
| handle[get] | std | Get underlying socket handle. | 
| hostName[get] | string | |
| isAlive[get] | bool | Property that indicates if this is a valid, alive socket. | 
| localAddress[get] | Address | Local endpoint Address. | 
| remoteAddress[get] | Address | Remote endpoint Address. | 
Methods
| Name | Description | 
|---|---|
| accept() | Accept an incoming connection. If the socket is blocking, acceptwaits for a connection request. ThrowsSocketAcceptExceptionif
 unable to accept. Seeacceptingfor use with derived classes. | 
| bind(addr) | Associate a local address with this socket. | 
| close() | Immediately drop any connections and release socket resources.
 The Socketobject is no longer usable afterclose.
 Callingshutdownbeforecloseis recommended
 for connection-oriented sockets. | 
| connect(to) | 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. | 
| getErrorText() | Get a text description of this socket's error status, and clear the socket's error status. | 
| getOption(level, option, result) | Get a socket option. | 
| getOption(level, option, result) | Common case of getting integer and boolean options. | 
| getOption(level, option, result) | Get the linger option. | 
| getOption(level, option, result) | Get a timeout (duration) option. | 
| listen(backlog) | Listen for an incoming connection. bindmust be called before you
 canlisten. Thebacklogis a request of how many pending
 incoming connections are queued untilaccepted. | 
| receive(buf, flags) | Receive data on the connection. If the socket is blocking, receivewaits until there is data to be received. | 
| receiveFrom(buf, flags, from) | Receive data and get the remote endpoint Address.
 If the socket is blocking,receiveFromwaits until there is data to
 be received. | 
| select(checkRead, checkWrite, checkError, timeout) | Wait for a socket to change status. A wait timeout of DurationorTimeVal, may be specified; if a timeout is not specified or theTimeValisnull, the maximum timeout is used. TheTimeValtimeout has an unspecified value whenselectreturns. | 
| send(buf, flags) | Send data on the connection. If the socket is blocking and there is no
 buffer space left, sendwaits. | 
| sendTo(buf, flags, to) | 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, sendTowaits. | 
| setKeepAlive(time, interval) | Enables TCP keep-alive with the specified parameters. | 
| setOption(level, option, value) | Set a socket option. | 
| setOption(level, option, value) | Common case for setting integer and boolean options. | 
| setOption(level, option, value) | Set the linger option. | 
| setOption(level, option, value) | Sets a timeout (duration) option, i.e. SocketOptionorRCVTIMEO. Zero indicates no timeout. | 
| shutdown(how) | Disables sends and/or receives. | 
| factory(classname) | Create instance of class specified by the fully qualified name classname. The class must either have no constructors or have a default constructor. | 
| opCmp(o) | Compare with another Object obj. | 
| opEquals(o) | Test whether thisis equal too.
 The default implementation only compares by identity (using theisoperator).
 Generally, overrides foropEqualsshould attempt to compare objects by their contents. | 
| toHash() | Compute hash function for Object. | 
| toString() | Convert Object to a human readable string. | 
| accepting() | Called by acceptwhen a newSocketmust be created for a new
 connection. To use a derived class, override this method and return an
 instance of your class. The returnedSocket's handle must not be
 set;Sockethas a protected constructorthis()to use in this
 situation. | 
| createAddress() | Can be overridden to support other addresses. | 
Authors
Christopher E. Miller, David Nadlinger, Vladimir Panteleev
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.