Why is that a problem in the first place? Sockets are very lightweight in just about any OS, and if you want 1 socket for 2 things then you are not going to be using the same socket to accept still so you can just close it and it gets freed anyways.