Пример #1
0
 def connect_targetID(self, targetID):
     try:
         wsurl = 'ws://{}:{}/devtools/page/{}'.format(
             self.host, self.port, targetID)
         self.close()
         self.ws = websocket.create_connection(wsurl)
         self.ws.settimeout(self.timeout)
     except:
         wsurl = self.tabs[0]['webSocketDebuggerUrl']
         self.ws = websocket.create_connection(wsurl)
         self.ws.settimeout(self.timeout)
Пример #2
0
 def testWebSocketWihtCustomHeader(self):
     s = ws.create_connection("ws://echo.websocket.org/",
                              headers={"User-Agent": "PythonWebsocketClient"})
     self.assertNotEqual(s, None)
     s.send("Hello, World")
     result = s.recv()
     self.assertEqual(result, "Hello, World")
     s.close()
Пример #3
0
 def connect(self, tab=0, update_tabs=True):
     if update_tabs or self.tabs is None:
         self.get_tabs()
     self.current_tab = self.tabs[tab]
     wsurl = self.tabs[tab]['webSocketDebuggerUrl']
     self.close()
     self.ws = websocket.create_connection(wsurl)
     self.ws.settimeout(self.timeout)
Пример #4
0
    def testWebSocket(self):
        s = ws.create_connection("ws://echo.websocket.org/")
        self.assertNotEqual(s, None)
        s.send("Hello, World")
        result = s.recv()
        self.assertEqual(result, "Hello, World")

        s.send(u"こにゃにゃちは、世界")
        result = s.recv()
        self.assertEqual(result, "こにゃにゃちは、世界")
        s.close()
Пример #5
0
 def testSecureWebSocket(self):
     if 1:
         import ssl
         s = ws.create_connection("wss://echo.websocket.org/")
         self.assertNotEqual(s, None)
         self.assertTrue(isinstance(s.sock, ssl.SSLSocket))
         s.send("Hello, World")
         result = s.recv()
         self.assertEqual(result, "Hello, World")
         s.send(u"こにゃにゃちは、世界")
         result = s.recv()
         self.assertEqual(result, "こにゃにゃちは、世界")
         s.close()
Пример #6
0
 def testSockOpt(self):
     sockopt = ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),)
     s = ws.create_connection("ws://echo.websocket.org", sockopt=sockopt)
     self.assertNotEqual(s.sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY), 0)
     s.close()
Пример #7
0
 def testAfterClose(self):
     s = ws.create_connection("ws://echo.websocket.org/")
     self.assertNotEqual(s, None)
     s.close()
     self.assertRaises(ws.WebSocketConnectionClosedException, s.send, "Hello")
     self.assertRaises(ws.WebSocketConnectionClosedException, s.recv)
Пример #8
0
 def testPingPong(self):
     s = ws.create_connection("ws://echo.websocket.org/")
     self.assertNotEqual(s, None)
     s.ping("Hello")
     s.pong("Hi")
     s.close()
Пример #9
0
 def testNext(self):
     sock = ws.create_connection('ws://stream.meetup.com/2/rsvps')
     self.assertEqual(str, type(next(sock)))
Пример #10
0
 def testIter(self):
     count = 2
     for _ in ws.create_connection('ws://stream.meetup.com/2/rsvps'):
         count -= 1
         if count == 0:
             break