|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我连接的是自己的电脑,怎么会有积极拒绝????
服务器:
from socket import *
from time import ctime
HOST = ''
PORT = 21567
BUFSIZ=1024
ADDR = (HOST,PORT)
tcpSerSock = socket(AF_INET,SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)
while True:
print('waiting for connection....')
tcpCliSock.addr=tcpSerSock.accept()
print('...connection from:',addr)
while True:
data = tcpCliSock.recv(BUFSIZ)
if not data :
break
tcpCliSock.send('[%s] %s' %(bytes(ctime(),'utf-8'),data))
tcpCliSock.close()
tcpCliSock.close()
客户端:from socket import *
HOST = '127.0.0.1'
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST,PORT)
tcpCliSock = socket(AF_INET,SOCK_STREAM)
tcpCliSock.connect(ADDR)
while True:
data = input('>')
if not data:
break
tcpCliSock.send(data)
data =tcpCliSock.recv(BUFSIZ)
if not data:
break
print(data,decode('utf-8'))
报错:Traceback (most recent call last):
File "C:/Users/wangyingh/Desktop/客户端.py", line 8, in <module>
tcpCliSock.connect(ADDR)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
|
|