python-Socket服务端无限循环接受客户端,但客户端一直处于接受服务端信息状态,无实际信息返回
服务端:#-*-coding=utf-8-*-fromsocketimport*fromtimeimport*host=''port=1234ADDR=(host,por...
服务端:
#-*- coding=utf-8 -*-from socket import *from time import *
host = ''port = 1234ADDR = (host,port)BUFSIZE = 2048
ss = socket(AF_INET,SOCK_STREAM) ss.bind(ADDR) ss.listen(5)
while True: print 'waiting for a client connection...' SockClientConnect,ClientAddr = ss.accept() print'...connection from:', ClientAddr while True: data = SockClientConnect.recv(BUFSIZE) if not data: break SockClientConnect.send('[%s] %s' %(ctime(),data)) SockClientConnect.close()ss.close()
客户端:
#-*- coding=utf-8 -*-from socket import *from urllib import localhost
host = 'localhost'port = 1234ADDR = (host,port)BUFFSIZ = 2048
ClientSock = socket(AF_INET,SOCK_STREAM)ClientSock.connect(ADDR)
try: while True: data = raw_input('>') if not data: break ClientSock.send(data) data = ClientSock.recv(BUFFSIZ) if not data: break print dataexcept socket.error: ClientSock.close()
ClientSock.close()
问题如题,谢谢 展开
#-*- coding=utf-8 -*-from socket import *from time import *
host = ''port = 1234ADDR = (host,port)BUFSIZE = 2048
ss = socket(AF_INET,SOCK_STREAM) ss.bind(ADDR) ss.listen(5)
while True: print 'waiting for a client connection...' SockClientConnect,ClientAddr = ss.accept() print'...connection from:', ClientAddr while True: data = SockClientConnect.recv(BUFSIZE) if not data: break SockClientConnect.send('[%s] %s' %(ctime(),data)) SockClientConnect.close()ss.close()
客户端:
#-*- coding=utf-8 -*-from socket import *from urllib import localhost
host = 'localhost'port = 1234ADDR = (host,port)BUFFSIZ = 2048
ClientSock = socket(AF_INET,SOCK_STREAM)ClientSock.connect(ADDR)
try: while True: data = raw_input('>') if not data: break ClientSock.send(data) data = ClientSock.recv(BUFFSIZ) if not data: break print dataexcept socket.error: ClientSock.close()
ClientSock.close()
问题如题,谢谢 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询