Fitblip / wsstat

Websocket stress testing made beautiful
MIT License
173 stars 24 forks source link

On Message Event #11

Open bharat-gera opened 6 years ago

bharat-gera commented 6 years ago

I have number of websocket connections connected,what if I want to send message on that connection from using some function. Do we have any utility function in the library for the same? I was trying to something like this:

import json from .clients import WebsocketTestingClient messageTypes = { 'handshake': 'hello', 'chan_register': 'register' } class WPushClient(WebsocketTestingClient):

def _construct_event_payload(self, request_type, **kwargs):
    data = dict()
    data['messageType'] = messageTypes[request_type]
    data.update(**kwargs)
    return json.dumps(data)

def _handshake_request(self):
    payload =  self._construct_event_payload('handshake', use_webpush=True)
    return payload

def after_connect(self, statedict):
    msg = self._handshake_request()
    self.logger.log(msg)
    statedict['connected_websocket'].ws.sendMessage(msg)

I was unable to send the "msg" on the websocket connection?