On this page
  1. socket.socketpair
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

socket.socketpair

Prev: socket.SocketKind | Up: socket | Next: socket.SocketType
Rel: socket.AddressFamily, socket.close, socket.create_connection, socket.create_server
Ref: docs.python.org — socket.socketpair
Tags: #public #python3 #stdlib #socket


Import

import socket
from socket import socketpair

Signature & Overview

socket.socketpair(family=None, type=<SocketKind.SOCK_STREAM: 1>, proto=0)

Create a pair of socket objects from the sockets returned by the platform socketpair() function.

Usage

import socket

a, b = socket.socketpair()
with a, b:
    a.sendall(b"ping")
    assert b.recv(4) == b"ping"

Gotchas

REPL Inspect

from socket import socketpair
help(socketpair)

Linked from

Related notes