import socket


try:
    while True:
        server_socket = socket.socket(
            socket.AF_INET,
            socket.SOCK_STREAM,
            socket.IPPROTO_TCP)

        address = ('127.0.0.1', 50000)
        server_socket.bind(address)
        server_socket.listen(1)

        connection, client_address = server_socket.accept()
        echo_msg = connection.recv(16)

        connection.sendall(echo_msg)
        connection.shutdown(socket.SHUT_WR)

except KeyboardInterrupt:
    return "Connection closing..."
    connection.close()

@@ -161,25 +161,24 @@
 TO_TCP)%0A
-%0A
         
 address 
@@ -169,26 +169,35 @@
         
-address = 
+server_socket.bind(
 ('127.0.
@@ -212,43 +212,8 @@
 000)
-%0A        server_socket.bind(address
 )%0A  
@@ -242,17 +242,16 @@
 sten(1)%0A
-%0A
         
@@ -301,16 +301,79 @@
 accept()
+%0A%0A        # receive message from client, and immediately return
 %0A       
@@ -404,17 +404,16 @@
 ecv(16)%0A
-%0A
         
@@ -440,16 +440,81 @@
 cho_msg)
+%0A%0A        # shutdown socket to writing after sending echo message
 %0A       
@@ -549,16 +549,43 @@
 SHUT_WR)
+%0A        connection.close()
 %0A%0Aexcept
@@ -612,53 +612,21 @@
     
-return %22Connection closing...%22%0A    connection
+server_socket
 .clo

Fix bug in server, connection closes after returning message, socket closes on KeyboardInterupt