![](/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.