


import socket
import urllib #needed for other features which i didn't include here for brievity
s = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
s.bind ( ( '', 8642 ) )
s.listen ( 1 )
while True:
channel, details = s.accept()
while(1):
data= channel.recv ( 100 )
command=data.split(" ")
if not data:
break
else:
if command[0] == "/terminate":
channel.send("Client exit")
channel.close()
s.close()
exit(1);
elif command[0] == "/quit":
channel.send("Client exit")
else:
print data
str="received: "+data
channel.send(str)
channel.close()
import socket
import urllib
print "<<CLIENT>>\n\n"
print ">>connecting to server...\n"
print ">>Attempting to connect to Server..."
s = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
CONNECT = 0
while CONNECT == 0:
try:
s.connect ( ( '127.0.0.1', 8642 ) )
except socket.error, msg:
continue
CONNECT = 1
print "\n>>Connected to server\n"
while (1):
data=raw_input(">> ")
if not data:
break
else:
if(s.send(data)):
retdata=s.recv(1000)
if (retdata != "Client exit" ):
print ">>Server: ",retdata,"\n"
else:
print ">>Closing connection"
s.close()
print ">>Connection terminated"
exit(1);
s.close()





Return to Interpreted Languages
Users browsing this forum: No registered users and 0 guests