【发布时间】:2018-08-22 15:10:07
【问题描述】:
我正在使用以下项目构建socket.io服务器:https://github.com/mrniko/netty-socketio
我的服务器:
public class ServerTest {
public static void main(String... args) {
Configuration config = new Configuration();
config.setPort(8080);
config.setAuthorizationListener(new AuthorizationListener() {
public boolean isAuthorized(HandshakeData handshakeData) {
System.out.println("yes!" + handshakeData.getAddress());
return true;
}
});
final SocketIOServer server = new SocketIOServer(config);
server.addEventListener("message", String.class, new DataListener<String>() {
public void onData(SocketIOClient socketIOClient, String s, AckRequest ackRequest) throws Exception {
System.out.println("hey");
}
});
server.start();
}
}
我接受所有连接,我已经使用 socket.io javascript 客户端测试了这样的连接:
var ws = io.connect('localhost:8080');
ws.on('connect', function() {
ws.emit('message', "I am a message!");
});
现在,我得到了打印“嘿”,但如果我发送这样的数据对象会怎样:
ws.emit('message', {data: "I am a message!"});
如何解码此消息?有没有办法调试发送到服务器的对象类型?
【问题讨论】: