Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+17 votes

I am getting an error message when sending my return message to the client list: "Error sending message to 127.0.0.1:64387: java.net.ConnectException: Connection refused (Connection refused); Removing client from list..." (basically the catch exception implemented in the method).

Now, I am creating a new socket with the client's address/port while iterating through the list (in order to set the output stream); I think this process is causing the error to occur. However, I do not know why as I am specifying the correct address/port for the client as the error clearly shows. Is anyone having the same issue?.

asked in CSC335_Spring2019 by (1 point)

1 Answer

+13 votes
 
Best answer

I think that the problem is that you shouldn't be creating a NEW socket, because there already is a socket which is still open, connected to that port.

Instead, you should be using the existing OutputStream object that is attached to the clientSocket that already exists.

(Of course, there could be other issues, but that's my hunch...)

answered by (508 points)
selected by
...