64
64
tuple, and the fields depend on the address type. The general tuple form is
65
65
``(addr_type, v1, v2, v3 [, scope])``, where:
67
- *addr_type* is one of TIPC_ADDR_NAMESEQ, TIPC_ADDR_NAME, or
69
- *scope* is one of TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, and
71
- If *addr_type* is TIPC_ADDR_NAME, then *v1* is the server type, *v2* is
67
- *addr_type* is one of :const:`TIPC_ADDR_NAMESEQ`, :const:`TIPC_ADDR_NAME`,
68
or :const:`TIPC_ADDR_ID`.
69
- *scope* is one of :const:`TIPC_ZONE_SCOPE`, :const:`TIPC_CLUSTER_SCOPE`, and
70
:const:`TIPC_NODE_SCOPE`.
71
- If *addr_type* is :const:`TIPC_ADDR_NAME`, then *v1* is the server type, *v2* is
72
72
the port identifier, and *v3* should be 0.
74
If *addr_type* is TIPC_ADDR_NAMESEQ, then *v1* is the server type, *v2*
74
If *addr_type* is :const:`TIPC_ADDR_NAMESEQ`, then *v1* is the server type, *v2*
75
75
is the lower port number, and *v3* is the upper port number.
77
If *addr_type* is TIPC_ADDR_ID, then *v1* is the node, *v2* is the
77
If *addr_type* is :const:`TIPC_ADDR_ID`, then *v1* is the node, *v2* is the
78
78
reference, and *v3* should be set to 0.
80
If *addr_type* is TIPC_ADDR_ID, then *v1* is the node, *v2* is the
80
If *addr_type* is :const:`TIPC_ADDR_ID`, then *v1* is the node, *v2* is the
81
81
reference, and *v3* should be set to 0.
83
83
- Certain other address families (:const:`AF_BLUETOOTH`, :const:`AF_PACKET`)
237
237
.. function:: create_connection(address[, timeout[, source_address]])
239
Convenience function. Connect to *address* (a 2-tuple ``(host, port)``),
240
and return the socket object. Passing the optional *timeout* parameter will
241
set the timeout on the socket instance before attempting to connect. If no
242
*timeout* is supplied, the global default timeout setting returned by
239
Connect to a TCP service listening on the Internet *address* (a 2-tuple
240
``(host, port)``), and return the socket object. This is a higher-level
241
function than :meth:`socket.connect`: if *host* is a non-numeric hostname,
242
it will try to resolve it for both :data:`AF_INET` and :data:`AF_INET6`,
243
and then try to connect to all possible addresses in turn until a
244
connection succeeds. This makes it easy to write clients that are
245
compatible to both IPv4 and IPv6.
247
Passing the optional *timeout* parameter will set the timeout on the
248
socket instance before attempting to connect. If no *timeout* is
249
supplied, the global default timeout setting returned by
243
250
:func:`getdefaulttimeout` is used.
245
252
If supplied, *source_address* must be a 2-tuple ``(host, port)`` for the
724
731
optional *flags* argument has the same meaning as for :meth:`recv` above.
725
732
Returns the number of bytes sent. Applications are responsible for checking that
726
733
all data has been sent; if only some of the data was transmitted, the
727
application needs to attempt delivery of the remaining data.
734
application needs to attempt delivery of the remaining data. For further
735
information on this topic, consult the :ref:`socket-howto`.
730
738
.. method:: socket.sendall(bytes[, flags])
879
887
:meth:`~socket.bind`, :meth:`~socket.listen`, :meth:`~socket.accept` (possibly
880
888
repeating the :meth:`~socket.accept` to service more than one client), while a
881
889
client only needs the sequence :func:`socket`, :meth:`~socket.connect`. Also
882
note that the server does not :meth:`~socket.send`/:meth:`~socket.recv` on the
883
socket it is listening on but on the new socket returned by
890
note that the server does not :meth:`~socket.sendall`/:meth:`~socket.recv` on
891
the socket it is listening on but on the new socket returned by
884
892
:meth:`~socket.accept`.
886
894
The first two examples support IPv4 only. ::
910
918
PORT = 50007 # The same port as used by the server
911
919
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
912
920
s.connect((HOST, PORT))
913
s.send(b'Hello, world')
921
s.sendall(b'Hello, world')
914
922
data = s.recv(1024)
916
924
print('Received', repr(data))