我正在尝试在服务器和客户端之间创建一个简单的多人连接。服务器不在网页上。服务器将打印正在运行的日志,并检测播放器何时连接和断开连接,并按预期方式写入日志。从理论上讲,当播放器连接服务器时,服务器应该向客户端发送一个ID,而当客户端收到该ID时,端侦听器应该将id打印出来,但是端侦听器永远不会触发,并且日志会打印出几条都显示以下消息:(HTTPLog)-Static :isSBSettingEnabled false
我正在遵循一个教程:https://www.youtube.com/watch?v=0t2wlvBJBUw&index=4&list=PLZm85UZQLd2Qh6r7jxBKPuB4hl-Xw5uZT,并且我已经三遍检查了我是否正确编写了所有内容。我尝试查找(HTTPLog)-Static:isSBSettingEnabled false,根据我所读的内容,这是一个与URL有关的Samsung专有问题,但我没有找到解决方案。我使用的网址是http://myIpAdress:8080。
服务器:
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
server.listen(8080, function(){
console.log("Server is now running");//This prints
});
io.on('connection', function(socket){
console.log("Player Connected");//This prints
socket.emit('socketID', { id: socket.id });
socket.on('disconnect', function(){
console.log("player disconnected");//This prints
});
});
我的主类中的代码:
private void connectSocket(){
try{
socket = IO.socket("http://---.---.--.-:8080");
socket.connect();
} catch (Exception e){
System.out.println("error: " + e);
}
}
private void configSocketEvents(){
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
System.out.println("socket.io, Connected");//This prints
}
}).on("socketID", new Emitter.Listener() {
@Override
public void call(Object... args) {
System.out.println("Is this running?");///Doesn't print
JSONObject data =(JSONObject) args[0];
try {
String id = data.getString("id");
System.out.println("SocketIO, My ID: " + id);
} catch (JSONException e) {
System.out.println("Socket.IO, JSONException " + e.toString());
}
}
});
}
我希望系统在建立连接时能打印出客户端ID,但是很明显,由于URL问题,socket.emit可能无法正常工作。