コード例 #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