I have a nodeJS server setup to accept socket connections, this seems to work fine with my web applications.
Now I'm trying to setup the same server to accept socket connections from Kryonet library on Android, iOS(Though RoboVM) & Desktop.
Node setup:
gameserver.js
var server = app.listen(9999, function()
{
var host = server.address().address;
var port = server.address().port;
console.log('Gameserver listening at http://%s:%s', host, port);
});
//Socket IO stuff.
var io = require('socket.io').listen(server);
require('./live_game_api.js')(io);
live_api.js
module.exports = function(io)
{
io.sockets.on('connection', function(socket)
{
console.log('user connected to server.');
socket.on('test', function(msg){
console.log('message: ' + msg);
});
});
}
Then within my app I've got:
new Thread(new Runnable() {
@Override
public void run()
{
try
{
Client client = new Client();
client.start();
client.addListener(new Listener() {
public void connected(Connection connection) {
PolyUtils.log("Connected");
}
@Override
public void disconnected(Connection connection) {
TextNotifierController.getInstance().displayTextBottom(UPStrings.Disconnected_from_mothership);
super.disconnected(connection);
}
@Override
public void received(Connection connection, Object object) {
PolyUtils.log("received:" + connection.isConnected());
super.received(connection, object);
}
@Override
public void idle(Connection connection) {
super.idle(connection);
}
});
//192.168.1.11:9999
client.connect(SOCKET_CONNECTION_TIMEOUT, ServerController.SOCKET_DOMAIN, ServerController.SOCKET_NUMBER, -1);
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
setupSocket();
}
});
}
catch(Exception exception)
{
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
hasConnection = false;
TextNotifierController.getInstance().displayText(UPStrings.Error_connecting_to_mothership, TextNotifierController.nearBottomVec);
}
});
exception.printStackTrace();
}
}
}).start();
I get the following error when connecting on the client:
00:00 INFO: Connecting: /192.168.1.11:9999
java.net.SocketTimeoutException: Connected, but timed out during TCP registration.