1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import socket import sys
messages = [ 'This is the message. ', 'It will be sent ', 'in parts.', ]
server_address = ('localhost', 10000)
socks = [ socket.socket(socket.AF_INET, socket.SOCK_STREAM), socket.socket(socket.AF_INET, socket.SOCK_STREAM), socket.socket(socket.AF_INET, socket.SOCK_STREAM), socket.socket(socket.AF_INET, socket.SOCK_STREAM), ]
print(sys.stderr, 'connecting to %s port %s' % server_address)
for s in socks: s.connect(server_address)
for message in messages:
for s in socks: print(sys.stderr, '%s: sending "%s"' % (s.getsockname(), message)) s.send(bytes(message,encoding='utf-8'))
for s in socks: data = s.recv(1024) print(sys.stderr, '%s: received "%s"' % (s.getsockname(), data)) if not data: print(sys.stderr, 'closing socket', s.getsockname()) s.close()
|