posted 20 years ago
Short lesson in the socket abstraction:
A ServerSocket "listens" on a specific port on the local machine. You can listen on any port you'd like, and unless some other process on the same machine is already listening on that same port (or unless it's a UNIX machine and the port number is less than 1024 and you're not root) it will succeed.
A Socket, on the other hand "contacts" a specific port on a remote machine. If there's no ServerSocket listening on the specified port on the remote machine, you'll see a "connection refused" error.
So in any event, it appears that on your friend's machine, there's a server process listening on the port that he used, and the code you show below successfully contacts that local server socket. But now you take the same code and run it on your own machine, it tries to contact a server process at the given port on your machine, and it fails, as you haven't got that server process running.
So what number is "port" in the original?