View source code
Display the source code in std/socket.d from which this page was generated on
github.
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.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Class std.socket.Socket
is a class that creates a network communication endpoint using
the Berkeley sockets interface.
Socket
Inherits from
-
(base class)Object
Constructors
Name | Description |
---|---|
this
|
Create a blocking socket. If a single protocol type exists to support
this socket type within the address family, the may be
omitted.
|
this
|
Use an existing socket handle .
|
this
|
Create a blocking socket using the parameters from the specified
structure.
|
this
|
Create a blocking socket. If a single protocol type exists to support
this socket type within the address family, the may be
omitted.
|
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 |
Returns the local machine's host name. |
isAlive
[get]
|
bool |
Property that indicates if this is a valid, alive socket. |
localAddress
[get]
|
Address |
Local endpoint .
|
remoteAddress
[get]
|
Address |
Remote endpoint .
|
Methods
Name | Description |
---|---|
accept
|
Accept an incoming connection. If the socket is blocking ,
waits for a connection request. Throws if
unable to accept. See for use with derived classes.
|
bind
|
Associate a local address with this socket. |
close
|
Immediately drop any connections and release socket resources.
Calling before is recommended for
connection-oriented sockets. The object is no longer
usable after .
|
connect
|
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 |
getOption
|
Get a socket option .
|
getOption
|
Common case of getting integer and boolean options. |
getOption
|
Get the linger option .
|
getOption
|
Get a timeout (duration) option .
|
listen
|
Listen for an incoming connection. must be called before you
can . The is a request of how many pending
incoming connections are queued until ed.
|
receive
|
Receive data on the connection. If the socket is blocking ,
waits until there is data to be received.
|
receiveFrom
|
Receive data and get the remote endpoint .
If the socket is blocking , waits until there is data to
be received.
|
select
|
Wait for a socket to change status. A wait timeout of or
, may be specified; if a timeout is not specified or the
is null , the maximum timeout is used. The
timeout has an unspecified value when returns.
|
send
|
Send data on the connection. If the socket is blocking and there is no
buffer space left, waits.
|
sendTo
|
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, waits.
|
setKeepAlive
|
Enables TCP keep-alive with the specified parameters. |
setOption
|
Set the linger option .
|
setOption
|
Set a socket option .
|
setOption
|
Common case for setting integer and boolean options. |
setOption
|
Sets a timeout (duration) option , i.e. or
RCVTIMEO . Zero indicates no timeout.
|
shutdown
|
Disables sends and/or receives. |
factory
|
Create instance of class specified by the fully qualified name
classname .
The class must either have no constructors or have
a default constructor.
|
opCmp
|
Compare with another Object obj.
|
opEquals
|
Returns !=0 if this object does have the same contents as obj.
|
toHash
|
Compute hash function for Object .
|
toString
|
Convert Object to a human readable string.
|
accepting
|
Called by when a new must be created for a new
connection. To use a derived class, override this method and return an
instance of your class. The returned 's handle must not be
set; has a protected constructor this() to use in this
situation.
|
createAddress
|
Returns a new Address object for the current address family.
|
Authors
Christopher E. Miller, David Nadlinger, Vladimir Panteleev