socket.socket()
socket.socket() is a Python function in the Socket Module category. Creates a socket for network communication. Default creates a TCP/IP socket. The syntax is socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0, fileno=None). Returns: Socket object. A typical example: import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("example.com", 80))
s.send(b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
data = s.recv(4096)
s.close(). A close sibling is socket.bind(), which binds the socket to a local address (host, port) for receiving connections. A close sibling is socket.listen(), which enables the socket to accept connection requests (server mode). A close sibling is socket.accept(), which accepts a connection. Returns (client_socket, client_address) tuple. A close sibling is socket.connect(), which connects the socket to a remote address (client mode). More about this category: Network communication — socket, connect, bind, listen, accept, send, recv. Related Socket Module entries: socket.bind(), socket.listen(), socket.accept(), socket.connect(), socket.send(), socket.sendall(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.