Python 实现的简单server-client demo

# coding:utf8  
  
'''''创建服务器端程序,用来接收客户端传进的数据'''  
  
from socket import *  
from time import ctime  
  
def server():  
    HOST = ''  
    PORT = 10521  
    ADDR = (HOST,PORT)  
    server_socket = socket(AF_INET,SOCK_STREAM)  
    server_socket.bind(ADDR)  
    server_socket.listen(5)  
    while True:  
        print 'Waiting for connecting ......'  
        tcpclientsocket,addr = server_socket.accept()  
        print 'Connected by ',addr  
        while True:  
            data = tcpclientsocket.recv(1024)  
            if not data:  
                break  
            print data  
            data = raw_input('I>')  
            tcpclientsocket.send('[%s]%s'%(ctime(),data))  
        tcpclientsocket.close()  
    server_socket.close()  
  
server()  

这篇文章容易理解:http://blog.csdn.net/u010278162/article/details/52045083 //client端

posted @ 2016-12-06 14:22  stma  阅读(687)  评论(0编辑  收藏  举报