File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 5
5
def client (msg ):
6
6
server_address = ('localhost' , 10000 )
7
7
sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
8
- print >> sys .stderr , 'connecting to %s port %s' % server_address
8
+ print >> sys .stderr , 'connecting to {0} port {1}' . format ( * server_address )
9
9
sock .connect (server_address )
10
10
try :
11
11
# Send data
12
- print >> sys .stderr , 'sending "%s"' % msg
12
+ print >> sys .stderr , 'sending "{0}"' . format ( msg )
13
13
sock .sendall (msg )
14
14
# Look for the response
15
15
amount_received = 0
16
16
amount_expected = len (msg )
17
17
while amount_received < amount_expected :
18
18
data = sock .recv (16 )
19
19
amount_received += len (data )
20
- print >> sys .stderr , 'received "%s"' % data
20
+ print >> sys .stderr , 'received "{0}"' . foramt ( data )
21
21
finally :
22
22
print >> sys .stderr , 'closing socket'
23
23
sock .close ()
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ def server():
6
6
address = ('127.0.0.1' , 10000 )
7
7
sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
8
8
sock .setsockopt (socket .SOL_SOCKET , socket .SO_REUSEADDR , 1 )
9
- print >> sys .stderr , "making a server on %s:%s" % address
9
+ print >> sys .stderr , "making a server on {0}:{1}" . format ( * address )
10
10
sock .bind (address )
11
11
sock .listen (1 )
12
12
@@ -15,16 +15,16 @@ def server():
15
15
print >> sys .stderr , 'waiting for a connection'
16
16
conn , addr = sock .accept () # blocking
17
17
try :
18
- print >> sys .stderr , 'connection - %s:%s' % addr
18
+ print >> sys .stderr , 'connection - {0}:{1}' . format ( * addr )
19
19
while True :
20
20
data = conn .recv (16 )
21
- print >> sys .stderr , 'received "%s"' % data
21
+ print >> sys .stderr , 'received "{0}"' . format ( data )
22
22
if data :
23
23
msg = 'sending data back to client'
24
24
print >> sys .stderr , msg
25
25
conn .sendall (data )
26
26
else :
27
- msg = 'no more data from %s:%s' % addr
27
+ msg = 'no more data from {0}:{1}' . format ( addr )
28
28
print >> sys .stderr , msg
29
29
break
30
30
finally :
You can’t perform that action at this time.
0 commit comments