Socket Object Methods

Socket objects have the following methods. Except for makefile() these correspond to system calls applicable to sockets.


\begin{funcdesc}{accept}{}
Accept a connection.
The socket must be bound to an a...
...e address bound
to the socket on the other end of the connection.
\end{funcdesc}


\begin{funcdesc}{bind}{address}
Bind the socket to an address. The socket must not already be bound.
\end{funcdesc}


\begin{funcdesc}{close}{}
Close the socket. All future operations on the socket ...
...Sockets are automatically closed when they are garbage-collected.
\end{funcdesc}


\begin{funcdesc}{connect}{address}
Connect to a remote socket.
\end{funcdesc}


\begin{funcdesc}{fileno}{}
Return the socket's file descriptor (a small integer). This is useful
with \code{select}.
\end{funcdesc}


\begin{funcdesc}{getpeername}{}
Return the remote address to which the socket is...
... to find out the port number of a remote IP socket, for instance.
\end{funcdesc}


\begin{funcdesc}{getsockname}{}
Return the socket's own address. This is useful to find out the port
number of an IP socket, for instance.
\end{funcdesc}


\begin{funcdesc}{getsockopt}{level\, optname\, buflen}
Return the value of the g...
...ode{struct} for a way to decode C structures
encoded as strings).
\end{funcdesc}


\begin{funcdesc}{listen}{backlog}
Listen for connections made to the socket.
The...
... and
should be at least 1; the maximum value is system-dependent.
\end{funcdesc}


\begin{funcdesc}{makefile}{mode}
Return a \dfn{file object} associated with the ...
...d socket object may be closed or
garbage-collected independently.
\end{funcdesc}


\begin{funcdesc}{recv}{bufsize\, flags}
Receive data from the socket. The return...
...eaning of the optional argument \var{flags}; it defaults to
zero.
\end{funcdesc}


\begin{funcdesc}{recvfrom}{bufsize}
Receive data from the socket. The return val...
... and \var{address} is the address of the
socket sending the data.
\end{funcdesc}


\begin{funcdesc}{send}{string}
Send data to the socket. The socket must be connected to a remote
socket.
\end{funcdesc}


\begin{funcdesc}{sendto}{string\, address}
Send data to the socket. The socket s...
...ket, since the destination socket is specified by
\code{address}.
\end{funcdesc}


\begin{funcdesc}{setsockopt}{level\, optname\, value}
Set the value of the given...
...odule
\code{struct} for a way to encode C structures as strings).
\end{funcdesc}


\begin{funcdesc}{shutdown}{how}
Shut down one or both halves of the connection. ...
...\var{how} is \code{2}, further sends and receives are
disallowed.
\end{funcdesc}

Note that there are no methods read() or write(); use recv() and send() without flags argument instead.