How to use the ws4py.client.threadedclient.WebSocketClient function in ws4py

To help you get started, we’ve selected a few ws4py examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github freenas / freenas / src / middlewared / middlewared / client / client.py View on Github external
from . import ejson as json
from protocol import DDPProtocol
from threading import Event, Thread
from ws4py.client.threadedclient import WebSocketClient

import argparse
import socket
import sys
import time
import uuid


class WSClient(WebSocketClient):
    def __init__(self, *args, **kwargs):
        self.client = kwargs.pop('client')
        self.protocol = DDPProtocol(self)
        super(WSClient, self).__init__(*args, **kwargs)

    def connect(self):
        self.sock.settimeout(10)
        rv = super(WSClient, self).connect()
        if self.sock:
            self.sock.settimeout(None)
        return rv

    def opened(self):
        self.protocol.on_open()

    def closed(self, code, reason=None):
github linkedin / mobster / src / linkedin / mobster / webkitcommunicator.py View on Github external
from collections import defaultdict
import json
import logging
from pprint import pformat
from Queue import Queue
import sys
import threading
import urllib2

from ws4py.client.threadedclient import WebSocketClient

from linkedin.mobster.mobsterconfig import config

class RemoteWebKitCommunicator(WebSocketClient):
  """
  Asynchronous interface for communicating with a remote WebKit-based browser 
  via remote debugging protocol. Currently tested only on desktop and Android 
  versions of Google Chrome.

  Chrome's documentation: 
  https://developers.google.com/chrome-developer-tools/docs/remote-debugging
  Latest WebKit Protocol Spec: 
  http://trac.webkit.org/browser/trunk/Source/WebCore/inspector/Inspector.json

  NOTE: The WebKit protocol spec may contain features unavailable in current 
  WebKit browser releases.
  """

  def __init__(self, page_num = 0):
    self._counter = 0
github syntithenai / opensnips / opensnips / old / docker-images / rasa / snips_services / KaldiClient.py View on Github external
def __init__(self, mqttClient, url,siteId, sessionId = None, protocols=None, extensions=None, heartbeat_freq=None, byterate=32000):
        WebSocketClient.__init__(self,url, protocols, extensions, heartbeat_freq)
        self.url = url
        self.siteId = siteId
        self.sessionId = sessionId
        self.client = mqttClient
github Lawouach / WebSocket-for-Python / example / droid_sensor.py View on Github external
self.terminate()
            
    def terminate(self):
        if not self.droid:
            return
        
        self.running = False
        self.droid.stopSensing()
        self.droid = None
        
        if not self.client.terminated:
            self.client.close()
            self.client._th.join()
            self.client = None
        
class AirPongWebSocketClient(WebSocketClient):
        def received_message(self, m):
            print m, len(str(m))

if __name__ == '__main__':
    aps = AirPongSensor(host='http://192.168.0.10:9000/ws')
    try:
        aps.run()
    except KeyboardInterrupt:
        aps.terminate()
github bq / web2board / src / libs / WSCommunication / Clients / WSHubsApi.py View on Github external
def constructAPIClientClass(clientClass):
    if clientClass is None:
        from ws4py.client.threadedclient import WebSocketClient
        clientClass = WebSocketClient
    class WSHubsAPIClient(clientClass):
        def __init__(self, api, url, serverTimeout):
            """
            :type api: HubsAPI
            """
            clientClass.__init__(self, url)
            self.__returnFunctions = dict()
            self.isOpened = False
            self.serverTimeout = serverTimeout
            self.api = api
            self.log = logging.getLogger(__name__)
            self.log.addHandler(logging.NullHandler())

        def opened(self):
            self.isOpened = True
            self.log.debug("Connection opened")
github DeForce / LalkaChat / modules / chat / deprecated / beampro.py View on Github external
RemoveMessageByUsers(
                nickname,
                platform=SOURCE
            )
        )

    def _post_process_multiple_channels(self, message):
        if self.main_class.get_config('config', 'show_channel_names'):
            message.channel_name = self.channel_nick

    def _send_message(self, message):
        self._post_process_multiple_channels(message)
        self.message_queue.put(message)


class BeamProClient(WebSocketClient):
    def __init__(self, url, **kwargs):
        WebSocketClient.__init__(self, url, protocols=['chat'], heartbeat_freq=30)
        self.exited = False

        self.channel_id = kwargs.get('channel_id')
        self.channel_nick = kwargs.get('channel_nick')
        self.main_class = kwargs.get('main_class')  # type: beampro
        self.id = 0

        self.ws_queue = Queue.Queue()
        self.message_handler = BeamProMessageHandler(
            queue=self.ws_queue,
            message_queue=self.main_class.queue,
            channel_nick=self.channel_nick,
            main_class=self.main_class
        )
github uts-magic-lab / rosduct / src / rosduct / rosbridge_client.py View on Github external
"""This module provides a python client for rosbridge to publish, subscribe topics,
call services, create service server and use action client.
"""

import threading
import time
import json
import uuid
from ast import literal_eval
from ws4py.client.threadedclient import WebSocketClient
# sudo pip install PyDispatcher
from pydispatch import dispatcher


class ROSBridgeClient(WebSocketClient):
    """ROSBridgeClient extends WebSocketClient and manages connection to the
    server and all interactions with ROS.

    It keeps a record of all publishers, subscriber, service request callbacks,
    service servers and action clients.
    """

    def __init__(self, ip, port=9090):
        """Constructor for ROSBridgeClient.

        Args:
            ip (str): The robot IP address.
            port (int, optional): The WebSocket port number for rosbridge.
                Defaults to 9090.
        """
        WebSocketClient.__init__(self, 'ws://{}:{}'.format(ip, port))
github LCAV / easy-dsp / browserinterface.py View on Github external
if bi_audio_start == None:
        bi_audio_start = datetime.datetime.now()

    time_diff = datetime.datetime.now() - bi_audio_start
    time_elapsed = time_diff.total_seconds()*1000 # in milliseconds
    audio_received = bi_audio_number*buffer_frames*1000/rate
    audio_delay = time_elapsed - audio_received
    r_messages.put(json.dumps({'latency': audio_delay}))
    bi_audio_number += 1

    # We call the callback
    cb(*params)

# Connection with WSAudio
class StreamClient(WebSocketClient):
    def received_message(self, m):
        global bi_audio_start
        global bi_audio_number
        global bi_recordings
        global bi_buffer
        global r_calls

        if not m.is_binary: # configuration data

            m = json.loads(m.data)

            try:

                global rate
                global channels
                global buffer_frames
github berkeleyopenarms / blue_interface / blue_interface / rosbridge_client.py View on Github external
def __init__(self, ip, port=9090):
        """Constructor for ROSBridgeClient

        Args:
            ip (str): The robot IP address.
            port (int, optional): The WebSocket port number for rosbridge. Defaults to 9090.
        """
        WebSocketClient.__init__(self, 'ws://{}:{}'.format(ip, port))
        self._connected = False
        self._id_counter = 0
        self._publishers = {}
        self._subscribers = {}
        self._services = {}
        self._action_clients = {}
        self.connect()
        th = threading.Thread(target=self.run_forever)
        th.daemon = True
        th.start()
        while not self._connected:
            time.sleep(0.1)
github alexazhou / GitAgent / gitagent / client.py View on Github external
def __init__(self, ip, port, console_receiver):
        self.websocket_id = None
        self.console_receiver = console_receiver
        url = "ws://%s:%s/console"%(ip, port)
        WebSocketClient.__init__(self, url, protocols=['http-only', 'chat'])