I am trying to modify a tcp/ip server-client communication. Only the server can communicate with the client. I am trying to find an easy a way to send a message back to the server. Not a chat !! Just a server which will send data to a client and receive data from the client.
I am using this example :
Server:
host="my_ip"
port=4446
from socket import *
s=socket()
s.bind((host,port))
s.listen(1)
print "Listening for connections.. "
q,addr=s.accept()
var = 1
while var == 1 :
data=raw_input("Enter data to be send: ")
q.send(data)
s.close()
Client:
host="my_ip"
port=4446
from socket import *
s=socket(AF_INET, SOCK_STREAM)
s.connect((host,port))
var = 1
while var == 1 :
msg=s.recv(1024)
print "Message from server : " + msg
#response = "Message delivered" # Response to be send
#s.sendto(response(host,port))
s.close()
Python actual has a built in class to make your life a bit easier. http://docs.python.org/2/library/socketserver.html. I'm not sure I understand the second part of your question however; you can simply send data back to the server in the same way you had the server send data to the client.