として、クライアントとsockjsノードとしてフェイ-のWebSocket-ノードとの問題私は、クライアントとサーバとしてsockjs-node 0.3.18
をfaye-websocket-node ^0.11.0
を使用しようとしているが、クライアント/サーバ・コードの下のNode.js - サーバー
問題を参照してください。 :
クライアントとサーバ
prefix
matchs場合、コードprefix = /hello
以下のように、クライアントは、私がトライError during WebSocket handshake: Unexpected response code: 200
がスローされますDサーバー上
prefix = /
を使用して、この時間は、すべてのエラーメッセージが表示されませんが、何も接続開いて、クライアントまたはサーバーon open
またはon connection
コードから印刷していないメッセージ
質問ありません:
は、クライアントとしてfaye-websocket-node
を使用する方法、サーバとしてsockjs-node
を使用し、node.jsを使用してwebsock経由で通信する方法
ありがとうございます!
クライアントコード:
var WebSocket = require('faye-websocket'),
ws = new WebSocket.Client('ws://127.0.0.1:8888/hello');
ws.on('open', function(event) {
console.log('open');
ws.send('Hello, world!');
});
ws.on('message', function(event) {
console.log('message', event.data);
});
ws.on('close', function(event) {
console.log('close', event.code, event.reason);
ws = null;
});
ws.on('error', function(event){
console.log('error', event.message);
});
サーバーコード:
var sockjs = require('sockjs');
var http = require('http');
var sockjsServer = sockjs.createServer({
sockjs_url: '//d1fxtkz8shb9d2.cloudfront.net/sockjs-0.3.min.js'
});
sockjsServer.on('connection', function(conn) {
console.log('on connection');
conn.on('data', function(msg) {
console.log('\nRECV:'+msg);
});
});
var server = http.createServer();
sockjsServer.installHandlers(server, {prefix:'/hello'});
server.listen(8888, '0.0.0.0');