Python create websocket client

tags: python  websocket  client  thread  Multithreading

Recently, I need to test the performance of the websocket server written by my colleagues. I wrote a test case for the convenience and practical python language, created 300 threads, and sent the heart all the time.

from websocket import create_connection
import threading
import time
def fun(arg):

    try:
        ws = create_connection("ws://192.168.100.45:8088")
        rr = arg+110102;

        print rr

        login0 = "{\"action\":\"client.login\",\"data\":{\"devid\":\"FFFFFFFF-CCC8-2E74-FFFF-FFFF83DD28B6\",\"location\":\"%s\"}}"%(str(rr))
        heart = "{\"action\":\"heart.info\",\"data\":{\"devid\":\"FFFFFFFF-CCC8-2E74-FFFF-FFFF83DD28B6\",\"location\":\""+ str(rr) + "\",\"heart\":\"ping\"}}"

        ws.send(login0)
        print login0
        print heart
        print arg
        while 1:

            time.sleep(3)
            ws.send(heart)
            result = ws.recv()
            print result

        ws.close()

    except Exception as e:
        print (e)


def fun2():
    for i in range(1,1) :
        ws = create_connection("ws://192.168.100.45:8088")
        ws.send("Hello, World")
        result = ws.recv()
        print result
        ws.close()



if __name__ == '__main__':
    try:
        for i in range(1, 300):

            t = threading.Thread(target=fun, args=(i,))
            t.start()
            #time.sleep(1)
            #t.join()

    except Exception as e:
        print (e)


    while 1:
        time.sleep(1)
        pass

 

Intelligent Recommendation

LibHV Tutorial 13 - Create a simple WebSocket client

Sample code referenceexamples/websocket_client_test.cpp Compilation operation:...

ws in node.js modules to create server and client, web client WebSocket

First, download the websocket module, the command line 1.node.js in the server module creates ws 2.node.js in ws module to create a client 3. Create a web client (using WebApi ---> WebSocket)  ...

How to create a websocket service in python

How to create a websocket service in python Server Client What does asyncio do? Description of some keywords for asyncio: Server Client What does asyncio do? Asynchronous network operation Concurrent ...

Create TCP Client with Python

Create TCP Client with Python...

Client stress testing for websocket using python

This code is found on github. Then simply modified it. Great God uses the process pool, as well as the contents of the thread pool. So save it, study and learn Then need to explain: this time using py...

More Recommendation

Client WebSocket

Why can't 80% of the code farmers can't do architects? >>>   Client In the browser that supports WebSocket, after creating a socket. You can respond to Socket by ONOpen, OnMessage, ...

SpringBoot+Netty Elegant Create WebSocket Client (Attached Source Code Download)

SpringBoot-CLI development scaffolding series Netty series: SpringBoot+Netty Create WebSocket client elegantly (attached source code download) Articles directory SpringBoot-CLI development scaffolding...

Python to create tcp server and client

Written in the front: Detailed address of the socket module function Create a tcp server: Create a tcp client:...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top