def Connect(self, url, timeout):
    """Connects the websocket.

    Raises:
      websocket.WebSocketException
      socket.error
    """
    assert not self._socket
    self._socket = websocket.create_connection(url, timeout=timeout)
    self._cur_socket_timeout = 0
    self._next_request_id = 0
Esempio n. 2
0
  def Connect(self, url, timeout=10):
    """Connects the websocket.

    Raises:
      websocket.WebSocketException
      socket.error
    """
    assert not self._socket
    self._socket = websocket.create_connection(url, timeout=timeout)
    self._cur_socket_timeout = 0
    self._next_request_id = 0
Esempio n. 3
0
  def testSockOpts(self):
    httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', 0), _FakeWebSocketHandler)
    ws_url = 'ws://127.0.0.1:%d' % httpd.server_port

    threading.Thread(target=httpd.handle_request).start()
    ws = websocket.create_connection(ws_url)
    try:
      self.assertNotEquals(
          ws.sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR), 0)
    finally:
      ws.close()

    threading.Thread(target=httpd.handle_request).start()
    ws = websocket.create_connection(
        ws_url,
        sockopt=[(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)])
    try:
      self.assertNotEquals(
          ws.sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR), 0)
      self.assertNotEquals(
          ws.sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY), 0)
    finally:
      ws.close()
Esempio n. 4
0
    def testSockOpts(self):
        httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', 0),
                                          _FakeWebSocketHandler)
        ws_url = 'ws://127.0.0.1:%d' % httpd.server_port

        threading.Thread(target=httpd.handle_request).start()
        ws = websocket.create_connection(ws_url)
        try:
            self.assertNotEquals(
                ws.sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR), 0)
        finally:
            ws.close()

        threading.Thread(target=httpd.handle_request).start()
        ws = websocket.create_connection(ws_url,
                                         sockopt=[(socket.IPPROTO_TCP,
                                                   socket.TCP_NODELAY, 1)])
        try:
            self.assertNotEquals(
                ws.sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR), 0)
            self.assertNotEquals(
                ws.sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY), 0)
        finally:
            ws.close()
Esempio n. 5
0
    def Connect(self, url, timeout):
        """Connects the websocket.

    Raises:
      websocket.WebSocketException
      socket.error
    """
        assert not self._socket

        # websocket-client uses a custom UTF8 validation implementation which is
        # immensely slow. Profiling shows validation of 15MB of tracing data takes
        # ~3min. https://crbug.com/753591.
        self._socket = websocket.create_connection(url,
                                                   timeout=timeout,
                                                   skip_utf8_validation=True)
        self._cur_socket_timeout = 0
        self._next_request_id = 0