I'm creating a MulticastSocket at a certain port and then joining a group. Now the socket keeps receiving datapackets as long as they are broadcasted. So I call the socket.receive in a while loop which is always true. Now I never leave the group. But If i terminate my program, does it close the socket automatically? I need some clarification on this.
Also, If I definitely need to leave said group and close the socket, how can I achieve that?. I have tried using addShutdownHook
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
System.out.println("Closing Broadcast Port");
multi.shutsocket();
}
}, "Shutdown-thread"));
But it's not working for some odd reason.