Bluemix

时间:2016-05-17 08:08:35

标签: python ibm-cloud

bluemix上是否有任何websocket客户端的工作示例?

我尝试了许多在Github中找到的例子,但它没有用。服务器是使用node red创建的,HTML实例可以与node red server进行通信。但是,python无法进行通信。 这是我的代码:

ws = create_connection("host name")
print "Sending 'Hello, World'..."
ws.send("Hello, World")
print "Sent"
print "Receiving..."
result =  ws.recv()
print "Received '%s'" % result

在上面的示例中,创建连接期间握手失败。我在互联网上尝试了很多其他的例子,但没有一个能够正常运作。

编辑:添加有关握手问题的更多详细信息:

DEBUG:root:--- request header ---
DEBUG:root:GET /ws/Test HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: tryandbuyoncloud.stage1.mybluemix.net
Origin: tryandbuyoncloud.stage1.mybluemix.net
Sec-WebSocket-Key1: 2 0{mN6 9 532X59  5V
Sec-WebSocket-Key2: } pp2B054402V  # _-5S8O0 kX

e�8��ۨ-
DEBUG:root:-----------------------
DEBUG:root:--- response header ---
DEBUG:root:HTTP/1.1 500 Error
DEBUG:root:Content-Type: text/plain; charset=UTF-8
DEBUG:root:X-Backside-Transport: FAIL FAIL
DEBUG:root:Connection: close

More details:
    487     ws = create_connection("ws://tryandbuyoncloud.stage1.mybluemix.net/ws/Test")
    488     print "Sending 'Hello, World'..."
    489     ws.send("Hello, World")

<ipython-input-96-f14c8986ac30> in create_connection(url, timeout, **options)
     86     websock = WebSocket()
     87     websock.settimeout(timeout != None and timeout or default_timeout)
---> 88     websock.connect(url, **options)
     89     return websock
     90 

<ipython-input-96-f14c8986ac30> in connect(self, url, **options)
    186         if is_secure:
    187             self.io_sock = _SSLSocketWrapper(self.sock)
--> 188         self._handshake(hostname, port, resource, **options)
    189 
    190     def _handshake(self, host, port, resource, **options):

<ipython-input-96-f14c8986ac30> in _handshake(self, host, port, resource, **options)
    222         if status != 101:
    223             self.close()
--> 224             raise WebSocketException("Handshake Status %d" % status)
    225         success, secure = self._validate_header(resp_headers)
    226         if not success:

WebSocketException: Handshake Status 500

0 个答案:

没有答案