Question: Can a computer, which acts as the Server, connect to itself more than once with a socket?
Background: I'm designing a game for my Java class that involves networking. So far in my code, I have one computer host the game via a ServerSocket while another computer connects to it via a Socket. For debugging purposes, I have been hosting the server and connecting to the server on the same computer. So as soon as I make a ServerSocket on port 3333 for instance, I also create a Socket by connecting to port 3333; and this is all on the same machine and IP address. However, what I have noticed is anytime I try to make more than one socket connection on the same machine, so two Sockets that both connect to the same ServerSocket on the same machine, the previous socket connection is closed. Why is that? The reason I am doing it this way is to make my life simpler when it comes to the code; this way, I can make the host act like another client and reuse code instead of implementing new one for a client that is host-sided.
Question: Can a computer, which acts as the Server, connect to itself more than once with a socket?
Yes. As long as the accepting side is implemented normally, i.e. to handle multiple clients, the computer doesn't care where the clients are coming from.