def _prepare_stream(self, host, port, which): import mod_pywebsocket.common from mod_pywebsocket.stream import Stream from mod_pywebsocket.stream import StreamOptions self._stream_name = which; self._socket = socket.create_connection(address=(host, port), timeout=self._options.socket_timeout) 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 _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)
now = str(datetime.now()) header = [center_freq, span, now] header_bin = struct.pack("II26s", *header) print "Trying to contact server..." try: 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),\