aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Client/Server string comunication problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Client/Server string comunication problem" Watch "Client/Server string comunication problem" New topic
Author

Client/Server string comunication problem

Pedro Neves
Ranch Hand

Joined: Mar 07, 2012
Posts: 64
hello. I'm experiencing some problems with sockets.

I'm trying to make a concurrent server to accept more than one clients.

When a client connects to the server, the server creates a new thread and listens to the socket.
Then, if the client sends something, the server must read it.

On the client i just open a dictionary (txt form) and i send it over the socket.

The problem is that when i read the content of the socket (on the server side) it throws the following exception:

java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:189)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.readLine(BufferedReader.java:317)
at java.io.BufferedReader.readLine(BufferedReader.java:382)
at RunnableThread.run(RunnableThread.java:38)
at java.lang.Thread.run(Thread.java:722)
at RunnableThread.<init>(RunnableThread.java:16)
at KnockKnockServer.main(KnockKnockServer.java:56)


where line 38 is " s = brIn.readLine(); "



the code is (just to document my statements):


SERVER



CLIENT





I just want to send the content of the file to the server side (which are just strings). I think my code its all right but it stills keep throwing that exception no matter what i do.

Thanks in advance.


Kind regards
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

It works fine for me. It reads the contents of the file, sends them to the server, which prints them out. Then the client exits without cleanly closing the socket so the server gives the exception, as expected.

As a side note, none of your new String(...)s are necessary.
Pedro Neves
Ranch Hand

Joined: Mar 07, 2012
Posts: 64
Jeff Verdegan wrote:It works fine for me. It reads the contents of the file, sends them to the server, which prints them out. Then the client exits without cleanly closing the socket so the server gives the exception, as expected.

As a side note, none of your new String(...)s are necessary.



Well if i run it i get:

ADDR# >>
localhost

Error: null


i debugged the server put a break point on lines:
s = brIn.readLine();
System.out.println(s);

and it stucks on the first one for once, then it never stops on this lines again.

This is stupid... it works with you but but not with me? What the Hell.


Kind regards




Pedro Neves
Ranch Hand

Joined: Mar 07, 2012
Posts: 64
Jeff Verdegan wrote:It works fine for me. It reads the contents of the file, sends them to the server, which prints them out. Then the client exits without cleanly closing the socket so the server gives the exception, as expected.

As a side note, none of your new String(...)s are necessary.



Ah.. and if it was printing was (i think) because i forget the System.out.println(strLine); :-/
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Client/Server string comunication problem