Socket Objects

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 \var{address}. The socket mus...
...at of \var{address} depends on the address family --- see above.)
\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 at \var{address}.
...
...at of \var{address} depends on the address family --- see above.)
\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...
...y ---
see above.) On some systems this function is not supported.
\end{funcdesc}


\begin{funcdesc}{getsockname}{}
Return the socket's own address. This is useful ...
...he address returned depends on the address family ---
see above.)
\end{funcdesc}


\begin{funcdesc}{getsockopt}{level\, optname\optional{\, buflen}}
Return the val...
...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...
...be at
least 1; the maximum value is system-dependent (usually 5).
\end{funcdesc}


\begin{funcdesc}{makefile}{\optional{mode\optional{\, bufsize}}}
Return a \dfn{f...
...terpreted the same way as by the built-in
\code{open()} function.
\end{funcdesc}


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


\begin{funcdesc}{recvfrom}{bufsize\optional{\, flags}}
Receive data from the soc...
...at of \var{address} depends on the address family --- see above.)
\end{funcdesc}


\begin{funcdesc}{send}{string\optional{\, flags}}
Send data to the socket. The s...
...ning as for
\code{recv()} above. Return the number of bytes sent.
\end{funcdesc}


\begin{funcdesc}{sendto}{string\optional{\, flags}\, address}
Send data to the s...
...at of \var{address} depends on the address family --- see above.)
\end{funcdesc}


\begin{funcdesc}{setblocking}{flag}
Set blocking or non-blocking mode of the soc...
...raised; in blocking mode, the calls block until they can proceed.
\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.