def socket_pair():
 port = socket()
 port.bind(('', 0))
 port.listen(1)
 client = socket()
 client.setblocking(False)
 client.connect_ex(('127.0.0.1', port.getsockname()[1]))
 client.setblocking(True)
 server = port.accept()[0]
 server.send(b('x'))
 assert (client.recv(1024) == b('x'))
 client.send(b('y'))
 assert (server.recv(1024) == b('y'))
 server.setblocking(False)
 client.setblocking(False)
 return (server, client)

def socket_pair ( ) : port = socket ( ) port . bind ( ( '' , 0 ) ) port . listen ( 1 ) client = socket ( ) client . setblocking ( False ) client . connect_ex ( ( '127.0.0.1' , port . getsockname ( ) [ 1 ] ) ) client . setblocking ( True ) server = port . accept ( ) [ 0 ] server . send ( b ( 'x' ) ) assert ( client . recv ( 1024 ) == b ( 'x' ) ) client . send ( b ( 'y' ) ) assert ( server . recv ( 1024 ) == b ( 'y' ) ) server . setblocking ( False ) client . setblocking ( False ) return ( server , client )
establish and return a pair of network sockets connected to each other .