0
在客戶端,我有這樣的代碼:Socket.io不從客戶端或服務器發送?
var serverAddress = "http://localhost:8081";
var socket = io(serverAddress);
socket.on('connect', function(){
console.log("Connected to server on %s", serverAddress);
});
socket.emit("xxx", {text : "attack"});
而且在服務器上,我有這樣的一個:
var express = require('express');
var http = require('http');
var app = express();
var server = http.createServer(app);
var socket = require('socket.io').listen(server);
socket.on('connect', function() {
console.log('A user is connected to server');
});
socket.on('xxx', function(data) {
console.log(data);
});
connect
事件被觸發,掛在了服務器,但xxx
事件不是連開火也沒有發現。怎麼了? Console.log
沒有報告任何錯誤。
這就是我一直在尋找的東西(y) –