我正在使用socket.io java client https://github.com/socketio/socket.io-client-java
显然,从那时起我一直坚持这个错误。
以下是我的代码:
socket = IO.socket("http://127.0.0.1:8000");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
System.out.println("Connection Successful");
socket.emit("foo", "hi");
}
});
Socket sock = socket.connect();
System.out.println(sock);
}catch(URISyntaxException exception){
exception.printStackTrace();
}
javascript部分如下:
<script>
var socket = io.connect('http://127.0.0.1:8000');
socket.on('connect', function(){
console.log("Hi! I am on");
});
socket.on('event', function(data){
console.log(data);
});
socket.on('disconnect', function(){
console.log("Bye! I am off");
});
</script>
任何解决方案?