damoxc committed 0038358

make py3 compatible

  • Participants
  • Parent commits 95c9567

Comments (0)

Files changed (1)

File examples/

 # this handler will be run for each incoming connection in a dedicated greenlet
 def echo(socket, address):
-    print 'New connection from %s:%s' % address
+    print ('New connection from %s:%s' % address)
     # using a makefile because we want to use readline()
     fileobj = socket.makefile()
     fileobj.write('Welcome to the echo server! Type quit to exit.\r\n')
     while True:
         line = fileobj.readline()
         if not line:
-            print "client disconnected"
+            print ("client disconnected")
         if line.strip().lower() == 'quit':
-            print "client quit"
+            print ("client quit")
-        print "echoed", repr(line)
+        print ("echoed %r" % line)
+    socket.close()
+    fileobj.close()
 if __name__ == '__main__':
     server = StreamServer(('', 6000), echo)
     # to start the server asynchronously, use its start() method;
     # we use blocking serve_forever() here because we have no other jobs
-    print 'Starting echo server on port 6000'
+    print ('Starting echo server on port 6000')