-1

我正在尝试使用 websocket 连接到 node.js 服务器。我正在开发一个 Phonegap 应用程序。当我尝试使用 iOS 6.x 模拟器连接时,它通过 websocket 完美地连接到服务器。但是使用 iOS 5.x 模拟器它没有连接。我看到当我运行代码时,它立即使用 ios 5.x 模拟器调用 onclose 方法。我正在使用 node.js 版本 0.10.17,也尝试使用 0.10.7。

我为 node.js 安装了 websocket 模块,这是我的客户端连接代码

function openConnection()
{
    // if user is running mozilla then use it's built-in WebSocket
    window.WebSocket = window.WebSocket || window.MozWebSocket;

    // if browser doesn't support WebSocket, just show some notification and exit
    if (!window.WebSocket)
    {
        alert("Sorry your browser does not support websockets");
        return;
    }
    // new socket

    connection = new WebSocket('ws://127.0.0.1:1337'); //change the ip address for online


    // push a message after the connection is established.

    connection.onopen = function()
    {   
        connection.send(sender_id); //change this iuserID in real case.
        //connection.send('Sample1');

        var message ="receive_offline_messages";    
        var message_to_be_sent = JSON.stringify({recevieruserid:sender_id,message:message});
        connection.send(message_to_be_sent);

        //Is the receiver online / offline
        var message ="get_delivery_report"; 
        var message_to_be_sent = JSON.stringify({message_sender_id:sender_id,message:message});
        connection.send(message_to_be_sent);

        connected_to_the_server=1;

        get_unsent_message();
        change_unsent_message_status();


    };
}

.....
4

1 回答 1

0

iOS 5 实现了 WebSocket 规范的早期草案版本

当前大多数基于服务器的 websocket 服务器仅支持最终确定的 WebSocket 规范 ( RFC-6455 )

在 HTTP Upgrade Request Handshake 中被视为以下标头...

Sec-WebSocket-Version: 13

此外,该站点跟踪许多浏览器的 websocket 支持级别。

http://caniuse.com/websockets

于 2013-08-22T15:35:37.920 回答