I've created 1 client server, but everytime I'm exiting the server I can't connect anymore
In order to fix this problem I need to change the port.
But the problem is that I did it like 8 times, so 8 ports are broken now..
When I'm writing bye, the server shuts down, but it seems like the port is still taken, what to do and how to fix it?
Thank you
53 Replies
⌛
This post has been reserved for your question.
Hey @Yarden! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Are you actually stopping the server process?
I'm doing this
Also something similar in the client
Are you also closing the ServerSocket?
Can you show the full class in a code block (NOT a screenshot)?
I do socket.close() so I think so no?
yes i will send you
It doesn't let me
it says it's too long
If you don't close
serverSocket
, the server will still be bound
skip the whole client handling codelikely still too much text
This message has been formatted automatically. You can disable this using
/preferences
.socket.close();
inputStreamReader.close();
outputStreamWriter.close();
bufferedReader.close();
bufferedWriter.close();
System.out.println("Socket closed: " + socket.isClosed());
This message has been formatted automatically. You can disable this using
/preferences
.Ok so why are you starting more server processes?
If a client disconnects, another client can connect
What do you mean?
How to avoid this?
Stop the server before starting a new one?
Why do you want to avoid that? Just don't start more servers?
I want this to be only 1 client server, so when the client disconnects I want the server to disconnects.
That's why I want to avoid that
The next level, the next program, will be for many clients, but I want to do this step by step
so the server should only handle a single client and then stop?
Yep once the client says "bye"
you already almost have that
then you don't need the loop
and also make sure you close
serverSocket
at the endThe guy in the tutorial said:
* The first loop: ensures the server is constantly running.
* The second loop: ensures that, once the client is connected, the server is constantly interacting with the client until the client disconnects.
Where was he wrong?
Maybe I've missed something?
I am talking about the outer loop
currently, your server is capable of handling multiple clients
fixed it thank youuu!
There is only 1 issue:
When i'm changing back the port to a port I already used before, I still got the error.
Is there a way to "free" the problematic ports?
that's exactly what your old version did
stop the servers that are still running
In the console view in Eclipse, you have these button
the red button stops the current program, the double-X clears the stopped consoles
so red button to stop the currently running program, then double-X to make it not show stopped programs, then the red button again to stop the currently shown program etc
doesn't work 🫠
The port is still broken
Show me the Eclipse console view
there's the double-X button as I said
you need to click that
and then the other button should turn red
I did also
I'll show you
And then i'm pressing f11 and i get an error
now since the button is red, you can click the red button to stop that process
then you click on the double-X again and on the red button again and on the double-X and on the red button until you stopped all servers
You are just a god
Thank you so much ❤️
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Last last last issue
When I'm trying to write a new line, it shows the marker on the existing server's message, but why?
I have the line "newLine()
It suppose to take 1 line space no?
Or maybe am I suppose to open a new help post?
?
Maybe you are using
System.out.print
instead of System.out.println
keep it open as long as you want to and close it if you think you are finished with itWait yes totally this
So i'm a bit confused, what exactly the use of newLine()?
I thought it take a line space
What do you mean with
newLine()
?Is that
BufferedWriter
going to System.out
?Hmmm probably not?
Isn't it "catch" the message the client writes in the system.out?
I mean the BufferedReader
And then the writer put it in the server's chat
How did you create
bufferedWriter
?
and what prints it to the console?
Are you using a BufferedReader
on the other side?I have InputStreamReader, the BufferedReader takes the information from the InputStreamReader.
The System.out prints in to the console no?
I'm using BufferedReader on both client and server sides
Can you show where this is received and printed to the console?
client or server?
socket = serverSocket.accept();
inputStreamReader = new InputStreamReader(socket.getInputStream()); outputStreamWriter = new OutputStreamWriter(socket.getOutputStream());
bufferedReader = new BufferedReader(inputStreamReader); bufferedWriter = new BufferedWriter(outputStreamWriter);
while(true) {
String msgFromClient = bufferedReader.readLine();
System.out.println("Client: " + msgFromClient);
bufferedWriter.write("MSG Received"); bufferedWriter.newLine(); bufferedWriter.flush();
inputStreamReader = new InputStreamReader(socket.getInputStream()); outputStreamWriter = new OutputStreamWriter(socket.getOutputStream());
bufferedReader = new BufferedReader(inputStreamReader); bufferedWriter = new BufferedWriter(outputStreamWriter);
while(true) {
String msgFromClient = bufferedReader.readLine();
System.out.println("Client: " + msgFromClient);
bufferedWriter.write("MSG Received"); bufferedWriter.newLine(); bufferedWriter.flush();
client
This message has been formatted automatically. You can disable this using
/preferences
.hm, that's weird
Right?
But it seems like everything is working pretyy much alright
So thank you very much ❤️
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@218019068219883520>.