Forums Register Login

Cannot read more than twice on BufferedReader/Inputstream

+Pie Number of slices to send: Send
As the title says i cannot read more than twice.
I can read the first line and than on the second time and on its giving me an exception.

Server:




Client:

+Pie Number of slices to send: Send
What is the exception?
+Pie Number of slices to send: Send
"Cannot read message"
+Pie Number of slices to send: Send
That's not the exception. That's the String you print out when you catch the IOException.

Trying printing the actual stacktrace. It should at least help you figure out which line is causing hte issue.
+Pie Number of slices to send: Send
Socket is closed
+Pie Number of slices to send: Send
I really know nothing about sockets and this kind of stuff, but if the problem is that the socket is closed, maybe you should not close it?
+Pie Number of slices to send: Send
Your server code looks a bit complicated. Why create an InputStreamReader (line 18), then wrap that in a BufferedReader (line 20), then read a line from that into a ByteArrayInputStream (encoding it using UTF-8), and then reading that again with a different BufferedReader and InputStreamReader (line 23; using the default character encoding which is not necessarily UTF-8)? It looks much more complicated than necessary.

Look at what your server code does. It accepts a client connection, then reads one line, prints it back, and then closes the connection. There's no loop anywhere to handle multiple lines.

Can you explain more clearly what exactly you expected both the server and client programs to do, what they actually do, and what the difference is between what you expected and what actually happens?
+Pie Number of slices to send: Send
I managed to work it
When i set up a loop on client the client always connected to the server with a new port or ip so it did not recognize the ip or port , Sorry if i can't explain it right.
Thanks anyway.
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2077 times.
Similar Threads
Chat At Server Part Both write and read at the same time?
Send message to all clients from server
Producer/Consumer Design impacts exception handling
Android java How to connect to server with different network/ip address
Send message from server to client any time
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:03:34.