2016-08-24 5 views
1

私は、ツイストwebsocketサーバーを使用して、ネットワークではなくlocalhost上のjavascriptクライアントに接続しようとしています。サーバーとクライアントはお互いを見ますが、ハンドシェイクを完了できません。はい、システム要件のためにtxWSが提供するHixie-76ラッパーを使用しています。なぜAutobahn Twisted Websocketサーバーがjavascriptクライアントとのハンドシェイクを完了していないのですか?

なぜ接続できないのですか?

バージョン:アウトバーン0.16、ツイスト0.16.3

これは私が達成しようとしているかの実際の例です。server.pyを使用して https://github.com/crossbario/autobahn-python/tree/master/examples/twisted/websocket/echoとclient.html

ログイン:

2016-08-24 15:44:33+0100 [-] Log opened. 
2016-08-24 15:44:33+0100 [-] WebSocketServerFactory (WebSocketFactory) starting on 8080 

2016-08-24 15:44:33+0100 [-] Starting factory <autobahn.twisted.websocket.WebSocketServerFactory object at 0x00000000031DB7F0> 

2016-08-24 15:44:33+0100 [-] Starting factory <txws.WebSocketFactory instance at 0x0000000002FA82C8> 

2016-08-24 15:44:34+0100 [MyServerProtocol (WebSocketProtocol),0,127.0.0.1] Starting HyBi-00/Hixie-76 handshake 

2016-08-24 15:44:34+0100 [MyServerProtocol (WebSocketProtocol),0,127.0.0.1] Completed HyBi-00/Hixie-76 handshake 

2016-08-24 15:44:39+0100 [-] WebSocket connection closed: 
2016-08-24 15:44:39+0100 [-] False 
2016-08-24 15:44:39+0100 [-] 1006 
2016-08-24 15:44:39+0100 [-] connection was closed uncleanly (peer did not finish (in time) the opening handshake) 

Pythonのクラス:

from txws import WebSocketFactory 
from twisted.internet import reactor 
from twisted.python import log 
from autobahn.twisted.websocket import WebSocketServerFactory 
from autobahn.twisted.websocket import WebSocketServerProtocol 

import json 
import sys 

class MyServerProtocol(WebSocketServerProtocol): 

    def onMessage(self, payload, isBinary): 
     print "Message Received!!!!" 
     msg = json.dumps({'status':'PLEASE WORK'}) 
     self.sendMessage(msg, isBinary=False) 

    def onClose(self, wasClean, code, reason): 
     print "WebSocket connection closed: " 
     print str(wasClean) 
     print str(code) 
     print str(reason) 

def make_server(): 
    print 'Making ws server' 
    log.startLogging(sys.stdout) 
    factory = WebSocketServerFactory("ws://127.0.0.1:8080") 
    factory.protocol = MyServerProtocol 
    reactor.listenTCP(8080, WebSocketFactory(factory)) #txWS WebSocketFactory wrapper 
    reactor.run() 

Javascript:

function ConnectWebSocket() { 
    websocket = new WebSocket('ws://127.0.0.1:8080'); 
    websocket_open = true; 

    websocket.onopen = function(e) { 
     console.log('opened'); 
     console.log(e); 
     websocket.send('slow test'); 
    }; 
    websocket.onclose = function(e) { 
     console.log("Connection closed."); 
     websocket_open = false; 
     websocket = null; 
     ConnectWebSocket(); 
    }; 
    websocket.onmessage = function(e) { 
     console.log('message'); 
     console.log(e.data); 
    }; 
    websocket.onerror = function(e) { 
     console.log('error'); 
     console.log(e); 
    }; 
} 
ConnectWebSocket(); 
+1

私はそれが問題になる可能性があります見ることができる唯一のことは、「U」は、 '(U「WS 8080://127.0.0.1」)に欠けているされて'これは単なるユニコードとして文字列をマークし、私から理解は通常大したことではありません。私はHixie-76ラッパーを使用したことがないので、 'WebSocketFactory(factory)'は他のすべてがうまくいくので問題がどこにあるのか推測しています。 –

答えて

0

問題が見つかりました。マイケルSはおそらくHixie-76ラッパーにあると示唆していたように、それはそうだった。開発者は、そのプロトコルが時間の経過とともにスリップしているはずで、もはや動作していないはずです。私はコードでそれを追跡することでこれを確認することができました。私はそれをtxWSの開発者に報告します。

私はHixie-76の問題への代替解決策を見つけました。私はhttps://github.com/gleicon/txwebsocketsでラッパーをtxWebSocketsに切り替えました。洗練されたソリューションではありませんが、現在は機能しています。

関連する問題