Why do I need to give the hostname in netty socketio and how to handle socketio in docker?

804 Views Asked by At

I am using netty-socketio for some project. I set up a server like so:

Configuration config = new Configuration();
config.setHostname("localhost");
config.setPort(8080);

SocketIOServer server = new SocketIOServer(config);
server.start();

I have only few knowledge on all this and I was wondering why do I need to set the hostname here? Wouldn't it be enough to just give the port to listen?

Also, how do I handle this in Docker: I have the IP of my server, and the virtual IP of the container, which one should I give?

What if I have another server running in a different container (but on the same machine) and I want the two to communicate, how can I handle all those IP to achieve this? And will the communication be as efficient as if it was all on localhost?

1

There are 1 best solutions below

0
On BEST ANSWER

As you can see here setting hostname can be easily omitted. Basically this is just an interface that will socketio be bound into. So yes, you can specify only the port to listen - in this scenario it will listen on 0.0.0.0.

When it comes to docker you may not specify the hostname but configure port exposing. E.g. container will listen on 0.0.0.0:8888 which will be exposed to :8889 - see port exposing.

All the containers will be running with their unique IP assigned. If you want them to communicate to just need to set different ports to be bound to.