に見ていない発しますサーバ。Node.jsのsocket.io - クライアント私は一緒にNode.jsの中の単純なSocket.IOのテストケースを置くしようとしているが、私はになって、クライアントから放射されたイベントが表示されませんサーバー
var http = require("http"),
io = require("socket.io"),
io_client = require("socket.io-client"),
listener, port, server, url,
socketServer, socketClient,
i = 0;
port = process.env.LISTEN_PORT || 80;
url = "http://localhost:" + port;
server = http.createServer();
socketServer = io(server);
socketClient = io_client(url);
socketServer.on("connection", function(socket) {
console.log("server:connection");
socket.emit("ping", ++i);
socket.on("pong", function(data) {
console.log("server:pong", data);
});
});
socketClient.on("ping", function(data) {
console.log("client:ping", data);
socketClient.emit("pong", data);
});
listener = server.listen(port, function() {
console.log("Listening on port " + listener.address().port);
});
期待出力
Listening on port 80
server:connection
client:ping 1
server:pong 1
実際の出力
Listening on port 80
server:connection
client:ping 1
接続は、データがサーバからクライアントに移動して作られているが、私は、対応する表示されませんクライアントがソケット・イベントをトリガーするときにサーバー上で発行されるイベント。
関連するクライアント送信コードを表示してください。 – jfriend00
ちょっと、ピンポンから名前を変更してください。 – Nivesh