python中socket无法连接到本地 提示Connection refused 100
服务器端代码importsocket#AddressHOST=''PORT=8000reply='Yes'#Configuresockets=socket.socket(...
服务器端代码
import socket
# Address
HOST = ''
PORT = 8000
reply = 'Yes'
# Configure socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
# passively wait, 3: maximum number of connections in the queue
s.listen(3)
# accept and establish connection
conn, addr = s.accept()
# receive message
request = conn.recv(1024)
print ('request is: ',request)
print ('Connected by', addr)
# send message
conn.sendall(reply.encode())
# close connection
conn.close()
客户端代码
import socket
# Address
HOST = '127.0.0.1'
PORT = 8000
request = 'can you hear me?'
# configure socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
# send message
s.sendall(request.encode())
# receive message
reply = s.recv(1024)
print ('reply is: ', reply.decode())
# close connection
s.close()
因为只有一台电脑所以连接到127.0.0.1
但提示 s.connect((HOST, PORT))
ConnectionRefusedError: [Errno 61] Connection refused
P.S. MAC系统 没有防火墙 展开
import socket
# Address
HOST = ''
PORT = 8000
reply = 'Yes'
# Configure socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
# passively wait, 3: maximum number of connections in the queue
s.listen(3)
# accept and establish connection
conn, addr = s.accept()
# receive message
request = conn.recv(1024)
print ('request is: ',request)
print ('Connected by', addr)
# send message
conn.sendall(reply.encode())
# close connection
conn.close()
客户端代码
import socket
# Address
HOST = '127.0.0.1'
PORT = 8000
request = 'can you hear me?'
# configure socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
# send message
s.sendall(request.encode())
# receive message
reply = s.recv(1024)
print ('reply is: ', reply.decode())
# close connection
s.close()
因为只有一台电脑所以连接到127.0.0.1
但提示 s.connect((HOST, PORT))
ConnectionRefusedError: [Errno 61] Connection refused
P.S. MAC系统 没有防火墙 展开
1个回答
2017-09-26
展开全部
如果您安装了最新的软件包v1.8.1
在发行说明中有一些说你需要chmod一个启动器文件
chmod +x /Users/_ENTER YOUR USERNAME_/Library/Application
Support/Sublime\ Text
3/Packages/OmniSharp/PrebuiltOmniSharpServer/omnisharp
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询