~ubuntu-branches/ubuntu/precise/python3.2/precise-proposed

« back to all changes in this revision

Viewing changes to Doc/library/socket.rst

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-03-09 18:40:39 UTC
  • mfrom: (30.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120309184039-j3yk2emxr1plyo21
Tags: 3.2.3~rc1-1
* Python 3.2.3 release candidate 1.
* Update to 20120309 from the 3.2 branch.
* Fix libpython.a symlink. Closes: #660146.
* Build-depend on xauth.
* Run the gdb tests for the debug build only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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:
66
66
 
67
 
  - *addr_type* is one of TIPC_ADDR_NAMESEQ, TIPC_ADDR_NAME, or
68
 
    TIPC_ADDR_ID.
69
 
  - *scope* is one of TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, and
70
 
    TIPC_NODE_SCOPE.
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.
73
73
 
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.
76
76
 
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.
79
79
 
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.
82
82
 
83
83
- Certain other address families (:const:`AF_BLUETOOTH`, :const:`AF_PACKET`)
236
236
 
237
237
.. function:: create_connection(address[, timeout[, source_address]])
238
238
 
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.
 
246
 
 
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.
244
251
 
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`.
728
736
 
729
737
 
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`.
885
893
 
886
894
The first two examples support IPv4 only. ::
898
906
   while True:
899
907
       data = conn.recv(1024)
900
908
       if not data: break
901
 
       conn.send(data)
 
909
       conn.sendall(data)
902
910
   conn.close()
903
911
 
904
912
::
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)
915
923
   s.close()
916
924
   print('Received', repr(data))
982
990
   if s is None:
983
991
       print('could not open socket')
984
992
       sys.exit(1)
985
 
   s.send(b'Hello, world')
 
993
   s.sendall(b'Hello, world')
986
994
   data = s.recv(1024)
987
995
   s.close()
988
996
   print('Received', repr(data))