![](/img/trans.png)
[英]socket connection refused: telnet: Unable to connect to remote host: Connection refused
[英]Socket disconnected after a message, (Connection refused by remote host), using python
我已经在azure上上传了我的python套接字(云服务项目),并且每当我连接到Hercules客户端套接字时……一两则消息之后,连接就被远程主机强制关闭了……?
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor
import SocketServer
class IphoneChat(Protocol):
def connectionMade(self):
self.factory.clients.append(self)
print('clients are'), self.factory.clients
def connectionLost(self, reason):
self.factory.clients.remove(self)
def dataReceived(self, data):
msg = ""
msg = data.strip()
for c in self.factory.clients:
c.message(msg)
def message(self, message):
self.transport.write(message + '\n')
print ('Iphone Chat server startedd')
factory = Factory()
factory.protocol = IphoneChat
factory.clients = []
reactor.listenTCP(9073, factory)
reactor.run()
我试图在我的环境中重现您的问题,但失败了。 根据我的经验,如果在天蓝色工作者角色中使用套接字,我们经常要注意3点。
考虑到工作者角色的状态,我建议我们可以将逻辑编码到while True
循环函数中,如下所示:
while True: reactor.listenTCP(65534, f) print "server run" reactor.run() sleep(1.0)
根据错误消息,我想原因是天蓝色的负载平衡器将在240秒内杀死空闲连接。 我建议您可以参考此博客来配置您的idleTimeoutInMinutes
值。
请尝试检查您的项目和配置。 任何进一步的发现,请让我知道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.