Comment faire pour envoyer un message à partir du serveur vers le client en python

Je suis en train de lire les deux programmes en Python 2.7.10 avec le client et le serveur. Comment puis-je modifier ces programmes afin d'envoyer un message à partir du serveur vers le client?

server.py:

#!/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

client.py:

#!/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

OriginalL'auteur Stamatis Papadopoulos | 2016-05-14