title: How to send a message from client to server in python
body: <p>I'm reading two programs in Python 2.7.10 with client and server. How can I modify these programs in order to send a message from client to server?</p>
  
  <p>server.py:</p>
  
  <pre><code>#!/usr/bin/python           # This is server.py file
  
  import socket               # Import socket module
  
  s = socket.socket()         # Create a socket object
  host = socket.gethostname() # Get local machine name
  port = 12345                # Reserve a port for your service.
  s.bind((host, port))        # Bind to the port
  
  s.listen(5)                 # Now wait for client connection.
  while True:
     c, addr = s.accept()     # Establish connection with client.
     print 'Got connection from', addr
     c.send('Thank you for connecting')
     c.close()                # Close the connection
  </code></pre>
  
  <p>client.py:</p>
  
  <pre><code>#!/usr/bin/python           # This is client.py file
  
  import socket               # Import socket module
  
  s = socket.socket()         # Create a socket object
  host = socket.gethostname() # Get local machine name
  port = 80              # Reserve a port for your service.
  
  s.connect((host, port))
  print s.recv(1024)
  s.close                     # Close the socket when done
  </code></pre>