I have a very simple question, however I am confused by a tutorial.
Say, I create a server & use port 1234:
ServerSocket server = new ServerSocket(1234);
Then, I ask server to wait for requests by:
while(true) {
// is the returned socket represents the server side socket or client side socket???
Socket socket = server.accept();
}
My question is whether the socket returned by server.accept()
a server side socket or client side socket? It is not very well explained in Java doc.
The reason why I ask this question is because when I run socket.getPort()
, it doesn't return server port 1234, instead, it returns a port not defined by me, so, I am thinking it might be the client's socket. But I am not sure.
Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.
which means, that it is server.
socket.getPort()
according to javadoc,
Returns the remote port number to which this socket is connected.