しばらくの間、自分のコードや設定が間違っているのを解明しようとしています。クライアントからサーバーにメッセージを送信したい。以下はすべてのブラウザで FF(11)とchrome(18.0.1025.152 m)を除いて動作します。ここでSocket.ioがChromeとFirefoxのノードサーバーにメッセージを送信できない
はいくつかの情報です:
- 私はポート8080で聞いている
- ローカルホストからページを提供するようにApacheを使用するWindows 7のエンタープライズ64ビットマシン
- 上のNode.jsを実行しますsocket.io
- でそれはChromeとFFのフォールバックXHRポーリング/ JSONPポーリングする代わりに、私は、サーバーからのメッセージをプッシュすることができ
- 使用してソケットのように見えますが、私はクライアントから放出することはできません
Serverコード:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World!</title>
<meta charset="utf-8">
<script src="http://localhost:8080/socket.io/socket.io.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var socket = io.connect('http://localhost:8080');
$("#button").click(function() {
socket.emit('my event' ,"Hello World!");
})
})
</script>
</head>
<body>
<button type="button" id='button'>Send Message</button>
</body>
</html>
モジュールのバージョン:
C:\Users\shlomis>npm ls
[email protected] C:\Users\shlomis
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
└─┬ [email protected]
├── [email protected]
├── [email protected]
└─┬ [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ └── [email protected]
└── [email protected]
var io = require('C:/Users/shlomis/node_modules/socket.io/lib/socket.io').listen(8080);
io.sockets.on('connection', function (socket) {
socket.on('my event', function (msg) {
console.log("DATA!!!");
});
});
私は完全なパスなしで
クライアントコードを必要とする方法を見つけることができませんでした
ノードログ:
C:\Users\shlomis>node C:\dev\wamp\www\AR\js\videoServer.js
info - socket.io started
debug - served static content /socket.io.js
debug - client authorized
info - handshake authorized 17502185141066845391
debug - setting request GET /socket.io/1/websocket/17502185141066845391
debug - set heartbeat interval for client 17502185141066845391
debug - client authorized for
debug - websocket writing 1::
debug - setting request GET /socket.io/1/xhr-polling/17502185141066845391?t=1334041653716
debug - setting poll timeout
debug - discarding transport
debug - cleared heartbeat interval for client 17502185141066845391
クロムWS要求(101のスイッチングプロトコル):
クロムXHR要求:
更新: Iv'eを添加
socket.on('connect', function() {
console.log("connected");
});
これは決してクロームでは発生しません。
何が間違っている可能性がありますか?助けてください:)
私はまったく同じ問題を持っています...クライアント上のsocket.emit( 'hello')は、safariでは動作しますが、firefoxやchromeでは動作しません。またはおそらくsocket.ioのバグです。 –
XHRを使用した場合にのみ障害が発生するため、「same-origin」ポリシーにすることはできますか? localhost:different-port-than-served-pageに簡単なXHRを作成してみてください。セキュリティ上の例外があるかどうか確認してください。 –
セキュリティ上の問題がなくなりました。私は現在、ノードJS上のソケットに対してhttp://faye.jcoglan.com/node.html(faye)を使用しています。これは正常に動作します... socket.ioのバグのようです。 –