• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Wasted 6 days on this and still can't get any message from chatClient

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i open server it's ok. But when client connect it throws error:
Server waiting for connection
Connection accepted from Socket[addr=/127.0.0.1,port=50409,localport=5000]
Server waiting for connection
mar 06, 2018 4:57:33 PM server.ServerHandler handle
SEVERE: null
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:337)
at java.io.DataInputStream.readUTF(DataInputStream.java:589)
at java.io.DataInputStream.readUTF(DataInputStream.java:564)
at server.ServerHandler.handle(ServerHandler.java:37)
at server.ServerHandler.run(ServerHandler.java:30)

Serwer Code:


Server Handler code:



ServerClient code:



ClientHandler Code:



 
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

SEVERE: null  


What is that message?  What is causing it?  Is the code hiding the full stack trace from a NPE?  Add a call to the printStackTrace method to see where the NPE happens and then find where the null value is.
Then change the code so there is no null value.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

SEVERE: null  


What is that message?  What is causing it?  Is the code hiding the full stack trace from a NPE?  Add a call to the printStackTrace method to see where the NPE happens and then find where the null value is.
Then change the code so there is no null value.


Here:


Server waiting for connection
Connection accepted from Socket[addr=/127.0.0.1,port=50458,localport=5000]
Server waiting for connection
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:337)
at java.io.DataInputStream.readUTF(DataInputStream.java:589)
at java.io.DataInputStream.readUTF(DataInputStream.java:564)
at server.ServerHandler.handle(ServerHandler.java:37)
at server.ServerHandler.run(ServerHandler.java:30)
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

SEVERE: null  


What is that message?  What is causing it?  Is the code hiding the full stack trace from a NPE?  Add a call to the printStackTrace method to see where the NPE happens and then find where the null value is.
Then change the code so there is no null value.


I think it was from here
at ServerHandler.class at       39 line.     Logger.getLogger(ServerHandler.class.getName()).log(Level.SEVERE, null, ex);
when i changed it to     ex.printStackTrace();
there is no null anymore.
 
Rancher
Posts: 4450
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's from the log() method.
The second parameter is any extra message that is to be added to the log entry.
In this case it's not really needed as the exception should be self explanatory.
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you debugging the code to see where the code is being executed?
Add lots of print statements to show where the code is being executed
and where it is not being executed.
 
Marshal
Posts: 24950
61
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You're extending Thread, and then you're overriding the run() method. Oh... never mind. I just looked and this ServerHandle inner class is totally unused, and there's a ServerHandler class elsewhere which does get used. Do us all a favour and delete ServerHandle. It's very distracting when you ask us to look at your code when it includes things which aren't ever used.
 
Paul Clapham
Marshal
Posts: 24950
61
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You create a ClientHandler object, which contains a Socket for the communication. But that's all you do. ClientHandler extends Thread, so shouldn't you be starting the Thread?

I'll also point out that even if you do start the Thread, that's going to result in calling ClientHandler's run() method, which does nothing.
 
Arek Wróbel
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That fixed everything, People take a lesson, don't code when you are not rested.
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!