Tuesday, July 29, 2014

PYTHON CLIENT SERVER PROGRAMS

#This is the Client
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("localhost",8001))
s.send("Ping")
result=s.recv(256)
print result

s.close()
#This is a python Server program
#!/usr/bin/env python
import socket
server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.bind(("localhost",8001))
server.listen(3)
while True:
    (client,address)=server.accept()
    msg=client.recv(100)
    print "received", msg
    client.send("pong")

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Biking helps me to cope with life.