import socket
import sys
HOST=''#Symbolic name meaning all available interfaces
PORT=8888#Arbitrary non-privileged port
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print 'Socket created!'
try:
	s.bind((HOST,PORT))
except socket.error, msg:
	print 'Bind failed.Error code: '+str(msg[0])+' Error message:'+msg[1]
	sys.exit()
print 'Socket bind successfully!'
s.listen(10)
print 'Now socket listening!'
#now keep talking with client
while 1:
	#wait to accept a connection -blocking call
	conn,addr=s.accept()
	#display client information
	print 'Connected with '+addr[0]+':'+str(addr[1])
	#now keep talking with the client
	data=conn.recv(1024)
	reply='OK...'+data
	if not data:
		break
	conn.sendall(reply)
conn.close()
s.close()