• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Client/Server string comunication problem

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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); :-/
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic