def connect(self, host, port, resource): self._socket = socket.socket() self.dictionary['server_port'] = port self.dictionary['server_host'] = host self.dictionary['resource'] = resource self._socket.settimeout(int(self.dictionary.get('socket_timeout'))) try: self._socket.connect((host, int(port))) self.isConnected = True if self.dictionary.get('use_tls') == 'True': self._socket = _TLSSocket(self._socket) version = self.dictionary.get('protocol_version') self._handshake = ClientHandshakeProcessor( self._socket, self.dictionary) self._handshake.handshake() request = ClientRequest(self._socket) version_map = { _PROTOCOL_VERSION_HYBI13: common.VERSION_HYBI13} request.ws_version = version_map[version] stream_option = StreamOptions() stream_option.mask_send = True stream_option.unmask_receive = False self._stream = Stream(request, stream_option) return OK_FLAG except Exception, e: self.isConnected = False print(e.message) return ERROR_FLAG
def run(self): """Run the client. Shake hands and then repeat sending message and receiving its echo. """ self._socket = socket.socket() self._socket.settimeout(self._options.socket_timeout) try: self._socket.connect( (self._options.server_host, self._options.server_port)) if self._options.use_tls: self._socket = _TLSSocket(self._socket) self._handshake = ClientHandshakeProcessor(self._socket, self._options) self._handshake.handshake() self._logger.info('Connection established') request = ClientRequest(self._socket) stream_option = StreamOptions() stream_option.mask_send = True stream_option.unmask_receive = False if self._options.use_permessage_deflate is not False: framer = self._options.use_permessage_deflate framer.setup_stream_options(stream_option) self._stream = Stream(request, stream_option) for line in self._options.message.split(','): self._stream.send_message(line) if self._options.verbose: print('Send: %s' % line) try: received = self._stream.receive_message() if self._options.verbose: print('Recv: %s' % received) except Exception as e: if self._options.verbose: print('Error: %s' % e) raise self._do_closing_handshake() finally: self._socket.close()
def _prepare_stream(self, host, port, which): self._stream_name = which; self._socket = socket.create_connection(address=(host, port), timeout=self._options.socket_timeout) uri = '/%d/%s' % (self._options.tstamp, which) handshake = ClientHandshakeProcessor(self._socket, host, port) handshake.handshake(uri) request = ClientRequest(self._socket) request.ws_version = mod_pywebsocket.common.VERSION_HYBI13 stream_option = StreamOptions() stream_option.mask_send = True stream_option.unmask_receive = False self._stream = Stream(request, stream_option)
def connect(self): self._socket = socket.socket() self._socket.settimeout(int(self.dictionary.get('socket_timeout'))) try: self._socket.connect((self.dictionary.get('server_host'), int(self.dictionary.get('server_port')))) if self.dictionary.get('use_tls') == 'True': self._socket = _TLSSocket(self._socket) version = self.dictionary.get('protocol_version') self._handshake = ClientHandshakeProcessor( self._socket, self.dictionary) self._handshake.handshake() self._logger.info('Connection established') request = ClientRequest(self._socket) version_map = { _PROTOCOL_VERSION_HYBI13: common.VERSION_HYBI13} request.ws_version = version_map[version] stream_option = StreamOptions() stream_option.mask_send = True stream_option.unmask_receive = False if self.dictionary.get('deflate_stream') == 'True': stream_option.deflate_stream = True if self.dictionary.get('deflate_frame') == 'True': processor = True processor.setup_stream_options(stream_option) self._stream = Stream(request, stream_option) listen = ListenSocket(self, self.received) write = WriteSocket(self, self.toSend) listen.start() write.start() finally: print "po powitaniu, serwer oczekuje na dane"
def _prepare_stream(self, host, port, which): import mod_pywebsocket.common from mod_pywebsocket.stream import Stream from mod_pywebsocket.stream import StreamOptions self._socket = socket.socket() self._socket.settimeout(10) # self._socket.settimeout(float(self._options[13])) self._socket.connect((host, port)) uri = '/%d/%s' % (int(time.time()), which) handshake = wsclient.ClientHandshakeProcessor(self._socket, host, port) handshake.handshake(uri) request = wsclient.ClientRequest(self._socket) request.ws_version = mod_pywebsocket.common.VERSION_HYBI13 stream_option = StreamOptions() stream_option.mask_send = True stream_option.unmask_receive = False self._stream = Stream(request, stream_option)
def connect(self, host, port, resource): self._socket = socket.socket() self.dictionary['server_port'] = port self.dictionary['server_host'] = host self.dictionary['resource'] = resource self._socket.settimeout(int(self.dictionary.get('socket_timeout'))) try: logger.logInfo(NAME + "connecting to " + host + ":" + str(port) + resource ) self._socket.connect((host, int(port))) if self.dictionary.get('use_tls') == 'True': self._socket = _TLSSocket(self._socket) version = self.dictionary.get('protocol_version') self._handshake = ClientHandshakeProcessor( self._socket, self.dictionary) self._handshake.handshake() logger.logInfo(NAME + 'Nawiazano polaczenie z ' + host+":"+str(port)) request = ClientRequest(self._socket) version_map = { _PROTOCOL_VERSION_HYBI13: common.VERSION_HYBI13} request.ws_version = version_map[version] stream_option = StreamOptions() stream_option.mask_send = True stream_option.unmask_receive = False self._stream = Stream(request, stream_option) return OK_FLAG except Exception, e: logger.logError(NAME+"Wystapil problem") logger.logError(NAME + e.message) print(e.message) return ERROR_FLAG
def connect(self, host, port, resource): self.dictionary['server_port'] = port self.dictionary['server_host'] = host self.dictionary['resource'] = resource self._socket = socket.socket() self._socket.settimeout(int(self.dictionary.get('socket_timeout'))) try: logging.info(NAME + "connecting to " + host + ":" + str(port) + resource ) self._socket.connect((host,int(port))) if self.dictionary.get('use_tls') == 'True': self._socket = _TLSSocket(self._socket) version = self.dictionary.get('protocol_version') self._handshake = ClientHandshakeProcessor( self._socket, self.dictionary) self._handshake.handshake() request = ClientRequest(self._socket) version_map = { _PROTOCOL_VERSION_HYBI13: common.VERSION_HYBI13} request.ws_version = version_map[version] stream_option = StreamOptions() stream_option.mask_send = True stream_option.unmask_receive = False self._stream = Stream(request, stream_option) logging.info(NAME+ "Polaczenie nawiazane") return CONNECTION_OK_FLAG except Exception, e: self._socket.close() logging.error(NAME+ "Nie mozna nawiazac polaczenia") logging.error(NAME + e.message) return CONNECTION_PROBLEM_FLAG
def run(self): """Run the client. Shake hands and then repeat sending message and receiving its echo. """ self._socket = socket.socket() self._socket.settimeout(self._options.socket_timeout) try: self._socket.connect((self._options.server_host, self._options.server_port)) if self._options.use_tls: self._socket = _TLSSocket( self._socket, self._options.tls_module, self._options.tls_version, self._options.disable_tls_compression) version = self._options.protocol_version if (version == _PROTOCOL_VERSION_HYBI08 or version == _PROTOCOL_VERSION_HYBI13): self._handshake = ClientHandshakeProcessor( self._socket, self._options) elif version == _PROTOCOL_VERSION_HYBI00: self._handshake = ClientHandshakeProcessorHybi00( self._socket, self._options) else: raise ValueError( 'Invalid --protocol-version flag: %r' % version) self._handshake.handshake() self._logger.info('Connection established') request = ClientRequest(self._socket) version_map = { _PROTOCOL_VERSION_HYBI08: common.VERSION_HYBI08, _PROTOCOL_VERSION_HYBI13: common.VERSION_HYBI13, _PROTOCOL_VERSION_HYBI00: common.VERSION_HYBI00} request.ws_version = version_map[version] if (version == _PROTOCOL_VERSION_HYBI08 or version == _PROTOCOL_VERSION_HYBI13): stream_option = StreamOptions() stream_option.mask_send = True stream_option.unmask_receive = False if self._options.deflate_frame is not False: processor = self._options.deflate_frame processor.setup_stream_options(stream_option) if self._options.use_permessage_deflate is not False: framer = self._options.use_permessage_deflate framer.setup_stream_options(stream_option) self._stream = Stream(request, stream_option) elif version == _PROTOCOL_VERSION_HYBI00: self._stream = StreamHixie75(request, True) for line in self._options.message.split(','): self._stream.send_message(line) if self._options.verbose: print('Send: %s' % line) try: received = self._stream.receive_message() if self._options.verbose: print('Recv: %s' % received) except Exception, e: if self._options.verbose: print('Error: %s' % e) raise self._do_closing_handshake()
mysocket = socket.socket() mysocket.connect((host, port)) except: print "Failed to connect, sleeping and reconnecting" exit() print "Socket open..." uri = '/%d/%s' % (int(time.time()), 'W/F') handshake = wsclient.ClientHandshakeProcessor(mysocket, host, port) handshake.handshake(uri) request = wsclient.ClientRequest(mysocket) request.ws_version = mod_pywebsocket.common.VERSION_HYBI13 stream_option = StreamOptions() stream_option.mask_send = True stream_option.unmask_receive = False mystream = Stream(request, stream_option) print "Data stream active..." # send a sequence of messages to the server, hardcoded for now msg_list = ['SET auth t=kiwi p=', 'SET zoom=%d start=%d'%(zoom,offset),\ 'SET maxdb=0 mindb=-100', 'SET wf_speed=4', 'SET wf_comp=0'] for msg in msg_list: mystream.send_message(msg) print "Starting to retrieve waterfall data..." # number of samples to draw from server length = options['length'] # create a numpy array to contain the waterfall data
print ("Trying to contact server...") try: kiwisocket = socket.socket() kiwisocket.connect((kiwihost, kiwiport)) except: print ("Failed to connect") exit() print ("Socket open...") uri = '/%d/%s' % (int(time.time()), 'W/F') handshake_wf = wsclient.ClientHandshakeProcessor(kiwisocket, kiwihost, kiwiport) handshake_wf.handshake(uri) request_wf = wsclient.ClientRequest(kiwisocket) request_wf.ws_version = mod_pywebsocket.common.VERSION_HYBI13 stream_option_wf = StreamOptions() stream_option_wf.mask_send = True stream_option_wf.unmask_receive = False wf_stream = Stream(request_wf, stream_option_wf) print ("Waterfall data stream active...") # send a sequence of messages to the server, hardcoded for now # max wf speed, no compression msg_list = ['SET auth t=kiwi p=%s'%kiwi_password, 'SET zoom=%d start=%d'%(zoom,cnt),\ 'SET maxdb=0 mindb=-100', 'SET wf_speed=4', 'SET wf_comp=0', 'SET maxdb=-10 mindb=-110'] for msg in msg_list: wf_stream.send_message(msg) print ("Starting to retrieve waterfall data...") ########################### SND connection # connect to kiwi server
def run(self): """Run the client. Shake hands and then repeat sending message and receiving its echo. """ self._socket = socket.socket() self._socket.settimeout(self._options.socket_timeout) try: self._socket.connect((self._options.server_host, self._options.server_port)) if self._options.use_tls: self._socket = _TLSSocket(self._socket) version = self._options.protocol_version if version == _PROTOCOL_VERSION_HYBI08 or version == _PROTOCOL_VERSION_HYBI13: self._handshake = ClientHandshakeProcessor(self._socket, self._options) elif version == _PROTOCOL_VERSION_HYBI00: self._handshake = ClientHandshakeProcessorHybi00(self._socket, self._options) elif version == _PROTOCOL_VERSION_HIXIE75: self._handshake = ClientHandshakeProcessorHixie75(self._socket, self._options) else: raise ValueError("Invalid --protocol-version flag: %r" % version) self._handshake.handshake() self._logger.info("Connection established") request = ClientRequest(self._socket) version_map = { _PROTOCOL_VERSION_HYBI08: common.VERSION_HYBI08, _PROTOCOL_VERSION_HYBI13: common.VERSION_HYBI13, _PROTOCOL_VERSION_HYBI00: common.VERSION_HYBI00, _PROTOCOL_VERSION_HIXIE75: common.VERSION_HIXIE75, } request.ws_version = version_map[version] if version == _PROTOCOL_VERSION_HYBI08 or version == _PROTOCOL_VERSION_HYBI13: stream_option = StreamOptions() stream_option.mask_send = True stream_option.unmask_receive = False if self._options.deflate_stream: stream_option.deflate_stream = True if self._options.deflate_frame is not False: processor = self._options.deflate_frame processor.setup_stream_options(stream_option) self._stream = Stream(request, stream_option) elif version == _PROTOCOL_VERSION_HYBI00: self._stream = StreamHixie75(request, True) elif version == _PROTOCOL_VERSION_HIXIE75: self._stream = StreamHixie75(request) for line in self._options.message.split(","): self._stream.send_message(line) if self._options.verbose: print "Send: %s" % line try: received = self._stream.receive_message() if self._options.verbose: print "Recv: %s" % received except Exception, e: if self._options.verbose: print "Error: %s" % e raise if version != _PROTOCOL_VERSION_HIXIE75: self._do_closing_handshake()