socket

Create a socket object.

Lightweight wrapper around the standard Berkeley sockets interface.

Classes

_class socket(object)

_let x = socket(family=AF_INET,type=SOCK_STREAM,proto=0)

socket.__init__(family=AF_INET,type=SOCK_STREAM,proto=0)

Creates a new socket object for the given address family and type.

_socket.accept()

Accept a connection on a listening socket.

Accepts one connection and returns a two-tuple with a new socket object and the address of the remote host.

_socket.bind(address)

Bind a socket to an address.

The format of address varies by address family. For AF_INET, address should be a two-tuple of a string domain name and integer port number.

_socket.connect(address)

Connect a socket to a remote endpoint.

As with socket_bind, the format of address varies.

_socket.fileno()

Get the file descriptor number for the underlying socket.

_socket.listen(backlog=0)

Set a bound socket to listen.

Begin listening on a bound socket, keeping backlog connections in a queue.

_socket.recv(bufsize,[flags])

Receive data from a connected socket.

Receive up to bufsize bytes of data, which is returned as a bytes object.

_socket.send(buf,[flags])

Send data to a connected socket.

Send the data in the bytes object buf to the socket. Returns the number of bytes written to the socket.

_socket.sendto(buf,[flags],addr)

Send data to an socket with a particular destination.

Send the data in the bytes object buf to the socket. Returns the number of bytes written to the socket.

_socket.setsockopt(level,optname,value)

Set socket options.

level and optname should be integer values defined by SOL and SO options. value must be either an int or a bytes object.

_socket.shutdown(how)

Shut down an active socket.

Gracefully closes an open socket.

_property socket.family

_property socket.proto

_property socket.type

Functions

_htons()

Exceptions

_class SocketError(BaseException)

Raised on faults from socket functions.

Constants

let AF_INET = 2

let AF_INET6 = 10

let AF_UNIX = 1

let SHUT_RD = 0

let SHUT_RDWR = 2

let SHUT_WR = 1

let SOCK_CLOEXEC = 524288

let SOCK_DGRAM = 2

let SOCK_NONBLOCK = 2048

let SOCK_RAW = 3

let SOCK_STREAM = 1

let SOL_SOCKET = 1

let SO_REUSEADDR = 2