Ejemplo n.º 1
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()
  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
    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()
Ejemplo n.º 4
0
 def Connect(self, url, timeout=10):
   assert not self._socket
   self._socket = websocket.create_connection(url, timeout=timeout)
   self._cur_socket_timeout = 0
   self._next_request_id = 0
 def Connect(self, url, timeout=10):
     assert not self._socket
     self._socket = websocket.create_connection(url, timeout=timeout)
     self._cur_socket_timeout = 0
     self._next_request_id = 0