简体   繁体   中英

Establish Concurrent Websocket Connections to server Using Python Twisted Websocket Client

I'm trying to open concurrent websocket connections from client end(which has 60k ports limit per machine) using Python Twisted Authobhan Websocket Client.But I'm unable to open not more than 20k connections using below code:

from autobahn.twisted.websocket import WebSocketClientProtocol, WebSocketClientFactory

class WebSocketClient(WebSocketClientProtocol):

    def _handshake_request(self):
        pass

    def onOpen(self):
        self._handshake_request()

    def onConnect(self, response):
        pass
    def onMessage(self,data):
        pass


class WebSocketFactory(WebSocketClientFactory):

    """WebSocketClient Factory"""

    protocol = WebSocketClient

if __name__ == '__main__':

    factory = WebSocketFactory()

    ##### Note here. ######
    for _ in range(num_connections):
        reactor.connectTCP(ws_url, ws_port, factory)
    #####

    reactor.run()

I have used "reactor.connectTCP" in a loop, Does it the correct way to open the concurrent websocket connections using Twisted?

Let me know.

You need to perform fewer concurrent connection attempts. You may be able to sustain 20k or more connections but you won't be able to establish them all simultaneously.

Limit yourself to a few dozen or a hundred at a time. You may want to use twisted.internet.task.cooperate for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM