tcp_server.py
from socket import * server = socket(AF_INET, SOCK_STREAM)
server.bind(('',12345))
server.listen(5)
print 'wait for connect...'
while True:
client,address = server.accept()
print address,client
while True:
data = client.recv(1024)
print data
send_data = raw_input('>')
if not send_data:
break
client.send(send_data)
client.close()
server.close()
tcp_client.py
from socket import * server = socket(AF_INET,SOCK_STREAM)
server.connect(('127.0.0.1',12345))
while True:
message = raw_input('client>')
if not message:
break
server.send(message)
data = server.recv(1024)
print 'recv is %s' % data
server.close()