socket
– TCP, UDP and RAW socket support¶
Warning
This module is disabled in 6.x and will removed in 7.x. Please use networking libraries instead. (Native networking will provide a socket compatible class.)
Create TCP, UDP and RAW sockets for communicating over the Internet.
-
class
socket.
socket
(family: int, type: int, proto: int)¶ Create a new socket
- Parameters
-
AF_INET
:int¶
-
AF_INET6
:int¶
-
SOCK_STREAM
:int¶
-
SOCK_DGRAM
:int¶
-
SOCK_RAW
:int¶
-
listen
(self, backlog: int) → None¶ Set socket to listen for incoming connections
- Parameters
backlog (int) – length of backlog queue for waiting connetions
-
accept
(self) → Tuple[socket, str]¶ Accept a connection on a listening socket of type SOCK_STREAM, creating a new socket of type SOCK_STREAM. Returns a tuple of (new_socket, remote_address)
-
send
(self, bytes: ReadableBuffer) → int¶ Send some bytes to the connected remote address. Suits sockets of type SOCK_STREAM
- Parameters
bytes (ReadableBuffer) – some bytes to send
-
recv_into
(self, buffer: WriteableBuffer, bufsize: int) → int¶ Reads some bytes from the connected remote address, writing into the provided buffer. If bufsize <= len(buffer) is given, a maximum of bufsize bytes will be read into the buffer. If no valid value is given for bufsize, the default is the length of the given buffer.
Suits sockets of type SOCK_STREAM Returns an int of number of bytes read.
- Parameters
buffer (WriteableBuffer) – buffer to receive into
bufsize (int) – optionally, a maximum number of bytes to read.
-
recv
(self, bufsize: int) → bytes¶ Reads some bytes from the connected remote address. Suits sockets of type SOCK_STREAM Returns a bytes() of length <= bufsize
- Parameters
bufsize (int) – maximum number of bytes to receive
-
sendto
(self, bytes: ReadableBuffer, address: Tuple[str, int]) → int¶ Send some bytes to a specific address. Suits sockets of type SOCK_DGRAM
- Parameters
bytes (ReadableBuffer) – some bytes to send
address (tuple(str, int)) – tuple of (remote_address, remote_port)
-
recvfrom
(self, bufsize: int) → Tuple[bytes, Tuple[str, int]]¶ Reads some bytes from the connected remote address. Suits sockets of type SOCK_STREAM
Returns a tuple containing * a bytes() of length <= bufsize * a remote_address, which is a tuple of ip address and port number
- Parameters
bufsize (int) – maximum number of bytes to receive