新手写的python简单服务器和客户端程序,纠错,python客户端程序,这是服务器的代码:#!/


这是服务器的代码:

#!/usr/bin/env python# -*- coding: utf-8 -*-import socketimport sysimport tracebackhost = ''port = 8080s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)s.bind((host, port))s.listen(3)while 1:    try:        conn, addr = s.accept()        print conn, addr        buf = s.recv(1024)        print buf    except socket.error:        print 'Error'        breaks.close()

这是客户端的代码:

    #!/usr/bin/env python# -*- coding: utf-8 -*-import socketimport tracebackhost = ''port = 8080s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)s.connect((host, port))data = 'x'*2048print len(data)pos = 0while pos < len(data)-1:        lpos = pos        rpos = min(len(data)-1, lpos + 1024)        pos += s.send(data[lpos:rpos])        print 'it has send %d'%rposwhile 1:    buf = s.recv(1024)    print '***', buf    if buf is '':        break    s.sendall(buf)s.close()

有点不知道怎么debug……服务器那边显示error,但是不知道是因为什么原因error……
想法是在客户端连入服务器后,向服务器发送1024字节的内容,然后服务器接收后把内容打出来,客户端把服务器信息也打印出来……
(⊙v⊙)嗯显然没有成功,求教求教!!~~~

抓errno,查py手册,包括socket错误号手册

编橙之家文章,

评论关闭