All Projects → sacOO7 → socketcluster-client-python

sacOO7 / socketcluster-client-python

Licence: MIT license
Python client for socket-cluster framework in node.js

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to socketcluster-client-python

etcd3-py
Pure python client for etcd v3 (Using gRPC-JSON-Gateway)
Stars: ✭ 97 (+106.38%)
Mutual labels:  python-client
BadMedicine
Library and CLI for randomly generating medical data like you might get out of an Electronic Health Records (EHR) system
Stars: ✭ 18 (-61.7%)
Mutual labels:  testing-tools
lyrebird-java-client
lyrebird-java-client 是Lyrebird的一个 Java SDK,通过调用Lyrebird本身提供的API实现在Java项目中控制 Lyrebird Services
Stars: ✭ 14 (-70.21%)
Mutual labels:  testing-tools
pymobird
A python client for memobird printer
Stars: ✭ 18 (-61.7%)
Mutual labels:  python-client
baset
Testing tool for baseline strategy
Stars: ✭ 26 (-44.68%)
Mutual labels:  testing-tools
react-native-unit-tests
Example how to test React Native components
Stars: ✭ 79 (+68.09%)
Mutual labels:  testing-tools
tools
Tools used for Penetration testing / Red Teaming
Stars: ✭ 63 (+34.04%)
Mutual labels:  testing-tools
dredd-rack
The Dredd API blueprint testing tool for your Rack applications.
Stars: ✭ 50 (+6.38%)
Mutual labels:  testing-tools
saloon
An E2E test seeder for enterprise web applications
Stars: ✭ 30 (-36.17%)
Mutual labels:  testing-tools
EyeJS
A JavaScript testing framework for the real world
Stars: ✭ 68 (+44.68%)
Mutual labels:  testing-tools
apitest
this is a tool for testing Laravel REST API
Stars: ✭ 11 (-76.6%)
Mutual labels:  testing-tools
eat
Json based scenario testing tool(which can have test for functional and non-functional)
Stars: ✭ 41 (-12.77%)
Mutual labels:  testing-tools
FakeDataGenerator
fakedatagenerator.herokuapp.com/
Stars: ✭ 18 (-61.7%)
Mutual labels:  testing-tools
testcontainers
Selenide + TestContainers (Docker) sample project
Stars: ✭ 28 (-40.43%)
Mutual labels:  testing-tools
test junkie
Highly configurable testing framework for Python
Stars: ✭ 72 (+53.19%)
Mutual labels:  testing-tools
jest-watch-suspend
Suspending jest watch mode
Stars: ✭ 13 (-72.34%)
Mutual labels:  testing-tools
sandboni-core
Sandboni - Java test optimization library which reduces test execution time without compromising quality
Stars: ✭ 27 (-42.55%)
Mutual labels:  testing-tools
ffbtools
Set of tools for FFB testing and debugging on GNU/Linux
Stars: ✭ 39 (-17.02%)
Mutual labels:  testing-tools
carina
Carina automation framework: Web, Mobile, API, DB etc testing...
Stars: ✭ 652 (+1287.23%)
Mutual labels:  testing-tools
Approvals.NodeJS
Approval Tests implementation in NodeJS
Stars: ✭ 79 (+68.09%)
Mutual labels:  testing-tools

socketcluster-client-python

Refer examples for more details :

Overview

This client provides following functionality

  • Easy to setup and use
  • Can be used for extensive unit-testing of all server side functions
  • Support for emitting and listening to remote events
  • Automatic reconnection
  • Pub/sub
  • Authentication (JWT)
  • Support for python2.x.x / python3.x.x

To install use

    sudo pip install socketclusterclient

Description

Create instance of Socket class by passing url of socketcluster-server end-point

    //Create a socket instance
    socket = Socketcluster.socket("ws://localhost:8000/socketcluster/") 
    

Important Note : Default url to socketcluster end-point is always ws://somedomainname.com/socketcluster/.

Registering basic listeners

Different functions are given as an argument to register listeners

        from socketclusterclient import Socketcluster
        import logging
        
        logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
        
        
        def onconnect(socket):
            logging.info("on connect got called")
        
        
        def ondisconnect(socket):
            logging.info("on disconnect got called")
        
        
        def onConnectError(socket, error):
            logging.info("On connect error got called")
        
        
        def onSetAuthentication(socket, token):
            logging.info("Token received " + token)
            socket.setAuthtoken(token)
        
        
        def onAuthentication(socket, isauthenticated):
            logging.info("Authenticated is " + str(isauthenticated))
            
            
        if __name__ == "__main__":
            socket = Socketcluster.socket("ws://localhost:8000/socketcluster/")
            socket.setBasicListener(onconnect, ondisconnect, onConnectError)
            socket.setAuthenticationListener(onSetAuthentication, onAuthentication)
            socket.connect()

Connecting to server

  • For connecting to server:
    //This will send websocket handshake request to socketcluster-server
    socket.connect();
  • By default reconnection to server is disabled (since latest release) , to enable it and configure delay for connection
    //This will set automatic-reconnection to server with delay of 2 seconds and repeating it for infinitely
   socket.setdelay(2)
   socket.setreconnection(True)
   socket.connect();
  • By default logging of messages in disabled (since latest release), to enable it
   socket.enablelogger(True)

Emitting and listening to events

Event emitter

  • eventname is name of event and message can be String, boolean, int or JSON-object
    socket.emit(eventname,message);
        
    # socket.emit("chat", "Hi")
  • To send event with acknowledgement
    socket.emitack("chat", "Hi", ack)  
        
    def ack(eventname, error, object):
        print "Got ack data " + object + " and error " + error + " and eventname is " + eventname

Event Listener

  • For listening to events :

The object received can be String, Boolean, Long or JSONObject.

     # Receiver code without sending acknowledgement back
     socket.on("ping", message)
     
     def message(eventname, object):
         print "Got data " + object + " from eventname " + eventname
  • To send acknowledgement back to server
    # Receiver code with ack
    socket.onack("ping", messsageack)
    
    def messsageack(eventname, object, ackmessage):
        print "Got data " + object + " from eventname " + eventname
        ackmessage("this is error", "this is data")
        

Implementing Pub-Sub via channels

Creating channel

  • For creating and subscribing to channels:
    
    # without acknowledgement
    socket.subscribe('yell')
    
    #with acknowledgement
    socket.subscribeack('yell', suback)
    
    def suback(channel, error, object):
        if error is '':
            print "Subscribed successfully to channel " + channel
  • For getting list of created channels :
        channels = socket.getsubscribedchannels()

Publishing event on channel

  • For publishing event :
       # without acknowledgement
       socket.publish('yell', 'Hi dudies')
       
       #with acknowledgement
       socket.publishack('yell', 'Hi dudies', puback)
       
       def puback(channel, error, object):
           if error is '':
               print "Publish sent successfully to channel " + channel

Listening to channel

  • For listening to channel event :
        
        socket.onchannel('yell', channelmessage)
    
        def channelmessage(key, object):
            print "Got data " + object + " from key " + key
    

Un-subscribing to channel

         # without acknowledgement
         socket.unsubscribe('yell')
         
         # with acknowledgement
         socket.unsubscribeack('yell', unsuback) 
         
         def unsuback(channel, error, object):
              if error is '':
                   print "Unsubscribed to channel " + channel 

Disable SSL Certificate Verification

        socket = Socketcluster.socket("wss://localhost:8000/socketcluster/")
        socket.connect(sslopt={"cert_reqs": ssl.CERT_NONE})

HTTP proxy

Support websocket access via http proxy. The proxy server must allow "CONNECT" method to websocket port. Default squid setting is "ALLOWED TO CONNECT ONLY HTTPS PORT".

        socket = Socketcluster.socket("wss://localhost:8000/socketcluster/")
        socket.connect(http_proxy_host="proxy_host_name", http_proxy_port=3128)
  • To have custom settings over internal logger, you can get logger instance and apply necessary settings over it.
        sclogger = socket.getlogger()

Please follow logging tutorial over here : https://docs.python.org/3/howto/logging-cookbook.html

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].