私は geddy フレームワーク (基本的なチャットの例) でリアルタイム アプリを実行しています。しかし、クライアントが接続を確立しようとすると、エラーが発生します。
サーバー側のコードは次のとおりです (init.js ファイル上):
var io = require('socket.io').listen(geddy.server);
io.sockets.on('connection', function (socket) {
console.log("Good!");
socket.emit('new', { message: 'world' });
socket.on('newMessage', function (data) {
console.log(data);
});
});
クライアント側のコード:
$(document).ready(function(){
startSockets();
});
function startSockets(){
var socket = io.connect('http://localhost:4004');
socket.on('new', function (data) {
alert(data);
//socket.emit('newMessage', { my: 'data' });
});
}
localhost:4004/ に接続しようとすると、次の警告が表示されます。
debug - setting request GET /socket.io/1/websocket/G_GapksVv1J4iBZIUVe3
debug - set heartbeat interval for client G_GapksVv1J4iBZIUVe3
debug - websocket writing 7:::1+0
warn - client not handshaken client should reconnect
info - transport end (error)
debug - set close timeout for client G_GapksVv1J4iBZIUVe3
debug - cleared close timeout for client G_GapksVv1J4iBZIUVe3
debug - cleared heartbeat interval for client G_GapksVv1J4iBZIUVe3
debug - discarding transport
Chromeコンソールに加えて、このエラーが発生します:
WebSocket is closed before the connection is established.
何がこれらの原因になるかわかりません。何か案は?