ID EN
Socket

socket

Python 3.11

Create a new socket using the given address family, socket type and protocol number. The address family should be AF_INET (the default), AF_INET6, AF_UNIX, AF_CAN, AF_PACKET, or AF_RDS. The socket type should be SOCK_STREAM (the default), SOCK_DGRAM, SOCK_RAW or perhaps one of the other SOCK_ constants. The protocol number is usually zero and may be omitted or in the case where the address family is AF_CAN the protocol should be one of CAN_RAW, CAN_BCM, CAN_ISOTP or CAN_J1939.

Syntax

PYTHON
class socket.socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)

Examples

Example 1
PYTHON
sock = socket.socket(
    socket.AF_INET,
    socket.SOCK_STREAM | socket.SOCK_NONBLOCK)

See Also

AF_INET AF_INET6 AF_UNIX AF_CAN AF_PACKET AF_RDS SOCK_STREAM SOCK_DGRAM