适用于Android应用的Meteor Backend的OpeningHandshakeException

时间:2017-04-09 08:58:34

标签: android meteor websocket reactive-programming

我刚刚使用简单meteor create hellometeor命令学习并实施了我的第一个Meteor应用,然后使用ngrok使localhost:3000端口生效。

然后我根据以下代码使用delight-im/Android-DDP库连接到直接ws网址:

    // create a new instance, where mMeteor is a global var.
    mMeteor = new Meteor(this, "ws://180a3c0e.ngrok.io", new InMemoryDatabase()); // "ws://180a3c0e.ngrok.io" is the temp. url after tunneling `localhost:3000`

    // register the callback that will handle events and receive messages
    mMeteor.addCallback(this); // as the activity implements MeteorCallback

    // establish the connection
    mMeteor.connect();

但是每次我尝试运行此代码时,我都会收到以下错误,因为我发现没有任何建议或直接的解决方案,对于像Meteor这样的新手来说就像平台一样过去6小时的谷歌搜索和阅读:

W/System.err: java.lang.Exception: com.neovisionaries.ws.client.OpeningHandshakeException: The status code of the opening handshake response is not '101 Switching Protocols'. The status line is: HTTP/1.0 502 Bad Gateway
W/System.err:     at im.delight.android.ddp.Meteor$1.onError(Meteor.java:195)
W/System.err:     at com.neovisionaries.ws.client.ListenerManager.callOnError(ListenerManager.java:432)
W/System.err:     at com.neovisionaries.ws.client.ConnectThread.handleError(ConnectThread.java:50)
W/System.err:     at com.neovisionaries.ws.client.ConnectThread.run(ConnectThread.java:41)
W/System.err: Caused by: com.neovisionaries.ws.client.OpeningHandshakeException: The status code of the opening handshake response is not '101 Switching Protocols'. The status line is: HTTP/1.0 502 Bad Gateway
W/System.err:     at com.neovisionaries.ws.client.HandshakeReader.validateStatusLine(HandshakeReader.java:232)
W/System.err:     at com.neovisionaries.ws.client.HandshakeReader.readHandshake(HandshakeReader.java:54)
W/System.err:     at com.neovisionaries.ws.client.WebSocket.readHandshake(WebSocket.java:3113)
W/System.err:     at com.neovisionaries.ws.client.WebSocket.shakeHands(WebSocket.java:2992)
W/System.err:     at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2034)
W/System.err:     at com.neovisionaries.ws.client.ConnectThread.run(ConnectThread.java:37)

可能我在Meteor服务器端缺少一个非常常见的东西,因为除了启动项目之外我还没有编写一行代码。
请赐教我这方面。
TIA。

1 个答案:

答案 0 :(得分:1)

我不应该知道Meteor在ws://.../websocket网址上有它的websocket连接,我应该被钉死在十字架上。

我刚刚在上一个网址的末尾添加了/websocket,所有内容都运行顺畅。