send & receive data over a socket python3
<p>I am attempting to send data after having prompted to enter text from keyboard input. The code seems to work, but the prompt does not appear. Can anybody suggest why?</p>

<p>Code to send is:</p>

<pre><code>  #!/usr/bin/python3
  import socket
  class LogSocket:
    def __init__(self, socket):
      self.socket = socket

    def send(self, data):
      print( "Sending {0} to {1}".format(data, self.socket.getpeername()[0]) )
      self.socket.send(data)

    def close(self):
      self.socket.close()

  def respond(client):
    response = input("Enter a value: ")
    client.send(bytes(response, 'utf8'))
    client.close()

  if __name__ == "__main__":
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.bind(('localhost',2401))
    server.listen(1)
    try:
      while True:
        client, addr = server.accept()
        respond(LogSocket(client))
    finally:
      server.close()
</code></pre>

<p>Code to receive is:</p>

<pre><code>#!/usr/bin/python3
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 2401))
print("Received: {0}".format(client.recv(1024)))
client.close()
</code></pre>

<p>The behaviour is a bit strange. When I enter "Hello World" in the sending terminal and then enter, when I switch over to the receiving terminal and run the receiving script, there is no output. When I again enter "Hello World" and hit enter in the sender, I then rerun the receiving script and "Hello World" appears, but with the prompt from input!</p>

<p>Sender output:</p>

<pre><code>Hello World
Enter a value: Sending b'' to 127.0.0.1
Hello World
Enter a value: Sending b'Hello World' to 127.0.0.1
</code></pre>

<p>Receiver output:</p>

<pre><code>$ ./receive_data_socket1.py 
Received: b''
$ ./receive_data_socket1.py 
Received: b'Hello World'
</code></pre>

<p>Could anybody with experience in dealing with sockets in Python3 explain the behaviour? I am aware that the behaviour has changed in 3.5, which is what I am using.</p>