import socket, sys
lstn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
lstn.bind(('', 2000))
lstn.listen(5)
v = ''
cs = []
nc = 2
for i in range(nc):
(clnt,ap) = lstn.accept()
clnt.setblocking(0)
cs.append(clnt)
while (len(cs) > 0):
clnt = cs.pop(0)
cs.append(clnt)
try:
k = clnt.recv(1)
if k == '':
clnt.close()
cs.remove(clnt)
v += k
clnt.send(v)
except: pass
lstn.close()
print 'the final value of v is', v
=============================================================
import socket, sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 2000))
while(1):
k = raw_input('enter a letter:')
s.send(k)
if k == '': break
v = s.recv(1024)
print v
s.close()