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();
};
}
.....