python client

转载 2013年12月03日 11:07:23
'''
Created on 2013年11月28日


@author: Administrator
'''
import socket,traceback
host=''
port=12345
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind((host,port))
s.listen(1)

while 1:
    try:
        clientsock,clientaddr=s.accept()
    except KeyboardInterrupt:
        raise
    except:
        traceback.print_exc()
        continue
    try:
        print ("连接来自:",clientsock.getpeername())
        while 1:
            data=clientsock.recv(4096)
            if not len(data):
                break
            print (clientsock.getpeername()[0]+':'+data.decode('utf-8'))
            clientsock.sendall(data)
            clientsock.sendall("\nI get it!\n".encode('utf-8'))
            t=input("input the word:")
            clientsock.sendall(t.encode(encoding='utf_8'))
    except (KeyboardInterrupt,SystemExit):
        raise
    except:
        traceback.print_exc()

    try:
        clientsock.close()
    except KeyboardInterrupt:
        raise
    except:
        traceback.print_exc()

内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:python client
举报原因:
原因补充:

(最多只允许输入30个字)