简体   繁体   中英

Java socket.io client portage

I got the nodeJS simpliest server running :

 var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); io.on('connection', function(socket){ console.log('a user connected'); }); http.listen(3000, function(){ console.log('listening on *:3000'); }); 

I got this usage example for the socket.io client java portage from the socket.io official github:

 socket = IO.socket("http://localhost:3000"); socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { @Override public void call(Object... args) { socket.emit("foo", "hi"); socket.disconnect(); } }).on("event", new Emitter.Listener() { @Override public void call(Object... args) {} }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() { @Override public void call(Object... args) {} }); socket.connect(); 

But the server is not receiving any connection, and the client either.. Someone already suceed to make it work? Thx

没关系,我刚刚创建了一个新项目,粘贴了所有相同的代码,它可以正常工作...我的项目可能以某种方式损坏了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM