mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
update demo scripts to use addr tuples for bind and connect
closes bug #111928
This commit is contained in:
parent
239f836c10
commit
a8d30d5d66
6 changed files with 9 additions and 9 deletions
|
@ -23,7 +23,7 @@ FINGER_PORT = 79
|
||||||
#
|
#
|
||||||
def finger(host, args):
|
def finger(host, args):
|
||||||
s = socket(AF_INET, SOCK_STREAM)
|
s = socket(AF_INET, SOCK_STREAM)
|
||||||
s.connect(host, FINGER_PORT)
|
s.connect((host, FINGER_PORT))
|
||||||
s.send(args + '\n')
|
s.send(args + '\n')
|
||||||
while 1:
|
while 1:
|
||||||
buf = s.recv(1024)
|
buf = s.recv(1024)
|
||||||
|
|
|
@ -48,7 +48,7 @@ def control(hostname):
|
||||||
# Create control connection
|
# Create control connection
|
||||||
#
|
#
|
||||||
s = socket(AF_INET, SOCK_STREAM)
|
s = socket(AF_INET, SOCK_STREAM)
|
||||||
s.connect(hostname, FTP_PORT)
|
s.connect((hostname, FTP_PORT))
|
||||||
f = s.makefile('r') # Reading the replies is easier from a file...
|
f = s.makefile('r') # Reading the replies is easier from a file...
|
||||||
#
|
#
|
||||||
# Control loop
|
# Control loop
|
||||||
|
@ -79,7 +79,7 @@ def newdataport(s, f):
|
||||||
port = nextport + FTP_DATA_PORT
|
port = nextport + FTP_DATA_PORT
|
||||||
nextport = (nextport+1) % 16
|
nextport = (nextport+1) % 16
|
||||||
r = socket(AF_INET, SOCK_STREAM)
|
r = socket(AF_INET, SOCK_STREAM)
|
||||||
r.bind(gethostbyname(gethostname()), port)
|
r.bind((gethostbyname(gethostname()), port))
|
||||||
r.listen(1)
|
r.listen(1)
|
||||||
sendportcmd(s, f, port)
|
sendportcmd(s, f, port)
|
||||||
return r
|
return r
|
||||||
|
|
|
@ -19,7 +19,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
port = PORT
|
port = PORT
|
||||||
s = socket(AF_INET, SOCK_STREAM)
|
s = socket(AF_INET, SOCK_STREAM)
|
||||||
s.bind('', port)
|
s.bind(('', port))
|
||||||
s.listen(1)
|
s.listen(1)
|
||||||
while 1:
|
while 1:
|
||||||
conn, (remotehost, remoteport) = s.accept()
|
conn, (remotehost, remoteport) = s.accept()
|
||||||
|
|
|
@ -51,7 +51,7 @@ def main():
|
||||||
s = socket(AF_INET, SOCK_STREAM)
|
s = socket(AF_INET, SOCK_STREAM)
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
s.connect(host, port)
|
s.connect((host, port))
|
||||||
except error, msg:
|
except error, msg:
|
||||||
sys.stderr.write('connect failed: ' + `msg` + '\n')
|
sys.stderr.write('connect failed: ' + `msg` + '\n')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -44,7 +44,7 @@ def server():
|
||||||
else:
|
else:
|
||||||
port = MY_PORT
|
port = MY_PORT
|
||||||
s = socket(AF_INET, SOCK_STREAM)
|
s = socket(AF_INET, SOCK_STREAM)
|
||||||
s.bind('', port)
|
s.bind(('', port))
|
||||||
s.listen(1)
|
s.listen(1)
|
||||||
print 'Server ready...'
|
print 'Server ready...'
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -72,7 +72,7 @@ def client():
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
s = socket(AF_INET, SOCK_STREAM)
|
s = socket(AF_INET, SOCK_STREAM)
|
||||||
t2 = time.time()
|
t2 = time.time()
|
||||||
s.connect(host, port)
|
s.connect((host, port))
|
||||||
t3 = time.time()
|
t3 = time.time()
|
||||||
i = 0
|
i = 0
|
||||||
while i < count:
|
while i < count:
|
||||||
|
|
|
@ -33,7 +33,7 @@ def server():
|
||||||
else:
|
else:
|
||||||
port = ECHO_PORT
|
port = ECHO_PORT
|
||||||
s = socket(AF_INET, SOCK_DGRAM)
|
s = socket(AF_INET, SOCK_DGRAM)
|
||||||
s.bind('', port)
|
s.bind(('', port))
|
||||||
print 'udp echo server ready'
|
print 'udp echo server ready'
|
||||||
while 1:
|
while 1:
|
||||||
data, addr = s.recvfrom(BUFSIZE)
|
data, addr = s.recvfrom(BUFSIZE)
|
||||||
|
@ -50,7 +50,7 @@ def client():
|
||||||
port = ECHO_PORT
|
port = ECHO_PORT
|
||||||
addr = host, port
|
addr = host, port
|
||||||
s = socket(AF_INET, SOCK_DGRAM)
|
s = socket(AF_INET, SOCK_DGRAM)
|
||||||
s.bind('', 0)
|
s.bind(('', 0))
|
||||||
print 'udp echo client ready, reading stdin'
|
print 'udp echo client ready, reading stdin'
|
||||||
while 1:
|
while 1:
|
||||||
line = sys.stdin.readline()
|
line = sys.stdin.readline()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue