Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_socket.py @ 8831:00a6bb65ff29 legacy-trunk
Getting rid of this ancient stuff.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 05 Aug 1998 21:10:09 +0000 |
| parents | aedd2d0dcb31 |
| children | dda3794c9cd9 |
| rev | line source |
|---|---|
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1 # Not tested: |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
2 # socket.fromfd() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
3 # sktobj.getsockopt() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
4 # sktobj.recvfrom() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
5 # sktobj.sendto() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
6 # sktobj.setblocking() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
7 # sktobj.setsockopt() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
8 # sktobj.shutdown() |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
9 |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
10 |
|
5520
31d66194a77c
Suppress fork part of socket test when we can't fork.
Guido van Rossum <guido@python.org>
parents:
5457
diff
changeset
|
11 from test_support import verbose, TestFailed |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
12 import socket |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
13 import os |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
14 import time |
|
4940
5eed51750284
Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents:
4914
diff
changeset
|
15 import string |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
16 |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
17 def missing_ok(str): |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
18 try: |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
19 getattr(socket, str) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
20 except AttributeError: |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
21 pass |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
22 |
|
6368
94e0b31fdf5f
Fixed test for socket.error to work when it's a class exception.
Guido van Rossum <guido@python.org>
parents:
5716
diff
changeset
|
23 try: raise socket.error |
|
94e0b31fdf5f
Fixed test for socket.error to work when it's a class exception.
Guido van Rossum <guido@python.org>
parents:
5716
diff
changeset
|
24 except socket.error: print "socket.error" |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
25 |
|
5457
53440097111f
Print less in test_socket.
Guido van Rossum <guido@python.org>
parents:
5060
diff
changeset
|
26 socket.AF_INET |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
27 |
|
5457
53440097111f
Print less in test_socket.
Guido van Rossum <guido@python.org>
parents:
5060
diff
changeset
|
28 socket.SOCK_STREAM |
|
53440097111f
Print less in test_socket.
Guido van Rossum <guido@python.org>
parents:
5060
diff
changeset
|
29 socket.SOCK_DGRAM |
|
53440097111f
Print less in test_socket.
Guido van Rossum <guido@python.org>
parents:
5060
diff
changeset
|
30 socket.SOCK_RAW |
|
53440097111f
Print less in test_socket.
Guido van Rossum <guido@python.org>
parents:
5060
diff
changeset
|
31 socket.SOCK_RDM |
|
53440097111f
Print less in test_socket.
Guido van Rossum <guido@python.org>
parents:
5060
diff
changeset
|
32 socket.SOCK_SEQPACKET |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
33 |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
34 for optional in ("AF_UNIX", |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
35 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
36 "SO_DEBUG", "SO_ACCEPTCONN", "SO_REUSEADDR", "SO_KEEPALIVE", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
37 "SO_DONTROUTE", "SO_BROADCAST", "SO_USELOOPBACK", "SO_LINGER", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
38 "SO_OOBINLINE", "SO_REUSEPORT", "SO_SNDBUF", "SO_RCVBUF", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
39 "SO_SNDLOWAT", "SO_RCVLOWAT", "SO_SNDTIMEO", "SO_RCVTIMEO", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
40 "SO_ERROR", "SO_TYPE", "SOMAXCONN", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
41 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
42 "MSG_OOB", "MSG_PEEK", "MSG_DONTROUTE", "MSG_EOR", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
43 "MSG_TRUNC", "MSG_CTRUNC", "MSG_WAITALL", "MSG_BTAG", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
44 "MSG_ETAG", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
45 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
46 "SOL_SOCKET", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
47 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
48 "IPPROTO_IP", "IPPROTO_ICMP", "IPPROTO_IGMP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
49 "IPPROTO_GGP", "IPPROTO_TCP", "IPPROTO_EGP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
50 "IPPROTO_PUP", "IPPROTO_UDP", "IPPROTO_IDP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
51 "IPPROTO_HELLO", "IPPROTO_ND", "IPPROTO_TP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
52 "IPPROTO_XTP", "IPPROTO_EON", "IPPROTO_BIP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
53 "IPPROTO_RAW", "IPPROTO_MAX", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
54 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
55 "IPPORT_RESERVED", "IPPORT_USERRESERVED", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
56 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
57 "INADDR_ANY", "INADDR_BROADCAST", "INADDR_LOOPBACK", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
58 "INADDR_UNSPEC_GROUP", "INADDR_ALLHOSTS_GROUP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
59 "INADDR_MAX_LOCAL_GROUP", "INADDR_NONE", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
60 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
61 "IP_OPTIONS", "IP_HDRINCL", "IP_TOS", "IP_TTL", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
62 "IP_RECVOPTS", "IP_RECVRETOPTS", "IP_RECVDSTADDR", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
63 "IP_RETOPTS", "IP_MULTICAST_IF", "IP_MULTICAST_TTL", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
64 "IP_MULTICAST_LOOP", "IP_ADD_MEMBERSHIP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
65 "IP_DROP_MEMBERSHIP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
66 ): |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
67 missing_ok(optional) |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
68 |
| 5716 | 69 socktype = socket.SocketType |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
70 hostname = socket.gethostname() |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
71 ip = socket.gethostbyname(hostname) |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
72 hname, aliases, ipaddrs = socket.gethostbyaddr(ip) |
|
4940
5eed51750284
Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents:
4914
diff
changeset
|
73 all_host_names = [hname] + aliases |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
74 |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
75 if verbose: |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
76 print hostname |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
77 print ip |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
78 print hname, aliases, ipaddrs |
|
4940
5eed51750284
Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents:
4914
diff
changeset
|
79 print all_host_names |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
80 |
|
4940
5eed51750284
Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents:
4914
diff
changeset
|
81 for name in all_host_names: |
|
5eed51750284
Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents:
4914
diff
changeset
|
82 if string.find(name, '.'): |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
83 break |
|
4940
5eed51750284
Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents:
4914
diff
changeset
|
84 else: |
|
5eed51750284
Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents:
4914
diff
changeset
|
85 print 'FQDN not found' |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
86 |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
87 print socket.getservbyname('telnet', 'tcp') |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
88 try: |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
89 socket.getservbyname('telnet', 'udp') |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
90 except socket.error: |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
91 pass |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
92 |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
93 |
|
5520
31d66194a77c
Suppress fork part of socket test when we can't fork.
Guido van Rossum <guido@python.org>
parents:
5457
diff
changeset
|
94 canfork = hasattr(os, 'fork') |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
95 try: |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
96 PORT = 50007 |
|
5520
31d66194a77c
Suppress fork part of socket test when we can't fork.
Guido van Rossum <guido@python.org>
parents:
5457
diff
changeset
|
97 if not canfork or os.fork(): |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
98 # parent is server |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
99 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
100 s.bind(hostname, PORT) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
101 s.listen(1) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
102 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
103 print 'parent accepting' |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
104 if canfork: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
105 conn, addr = s.accept() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
106 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
107 print 'connected by', addr |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
108 # couple of interesting tests while we've got a live socket |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
109 f = conn.fileno() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
110 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
111 print 'fileno:', f |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
112 p = conn.getpeername() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
113 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
114 print 'peer:', p |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
115 n = conn.getsockname() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
116 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
117 print 'sockname:', n |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
118 f = conn.makefile() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
119 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
120 print 'file obj:', f |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
121 while 1: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
122 data = conn.recv(1024) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
123 if not data: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
124 break |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
125 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
126 print 'received:', data |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
127 conn.send(data) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
128 conn.close() |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
129 else: |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
130 try: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
131 # child is client |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
132 time.sleep(5) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
133 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
134 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
135 print 'child connecting' |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
136 s.connect(hostname, PORT) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
137 msg = 'socket test' |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
138 s.send(msg) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
139 data = s.recv(1024) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
140 if msg <> data: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
141 print 'parent/client mismatch' |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
142 s.close() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
143 finally: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
144 os._exit(1) |
|
5520
31d66194a77c
Suppress fork part of socket test when we can't fork.
Guido van Rossum <guido@python.org>
parents:
5457
diff
changeset
|
145 except socket.error, msg: |
|
31d66194a77c
Suppress fork part of socket test when we can't fork.
Guido van Rossum <guido@python.org>
parents:
5457
diff
changeset
|
146 raise TestFailed, msg |
