Hello, all
I'm a new learner in
Java and I'm reading the Head First Java(2nd). I found one qustion about the ServerSocket in the chapter 15,page 483,"Writing a simple server" Step 3 in "How it works"
The code:
ServerSocket serverSock=new ServerSocket(4242);
Socket sock=serverSock.accept();
Head First Java said,"When a client finally tries to connect, the method returns a plain old Socket(on a different port) that knows how to communicate with the client. The Socket is on a
different port than the ServerSocket, so that the ServerSocket can go back to waiting for other clients."
I found this is different with what I thought before.
The Java Tutorials said "when a connection is requested and successfully established, the accept method returns a new Socket object which is bound to the
same local port(4242 in this case) and has it's remote address and remote port set to that of the client. "
see here I've tested and it also shows that the port number of the Sockte object which the method accept() returns is the SAME of the ServerSocket(4242 in this case).
I wonder whether there is something wrong with what Head First Java said here? Or, did I understood incorrectly?
Thanks so much!
[ February 20, 2007: Message edited by: Silvester Du ]
[ February 20, 2007: Message edited by: Silvester Du ]
[ February 20, 2007: Message edited by: Silvester Du ]