• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.net.SocketException: Error

 
Ranch Hand
Posts: 507
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Please have a look at the following two set of code, the server code and the client code

UserRegistrationServer.java



UserRegisterClient.java



In here, it is throwing an exception "java.net.SocketException: Software caused connection abort: recv failed" after the first data entry attempt, which means from the second data entry onwards. I have no idea why this is. This exception is caught in the client application. Please help me. Thanks.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The server closes the connection after sending its response.

Your protocol is not working. Your server accepts a new connection, reads from it, writes to it, then closes it. Your client creates a new connection, writes to it, reads from it, and then expects it to remain open.

I see two options:
1) in the server, keep the connection open. You will need a new thread that keeps reading from and writing to the connection, or you will block new connections.
2) in the client, don't store the socket and the streams globally, but reconnect and recreate the streams when pressing the button only.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great, excellent and perfect!! Thanks a lot Rob Spoor!! I really appreciate your help


I am posting my corrected code for others that who seek help for the same issue

UserRegisterClient.java



UserRegistrationServer.java




UserRegistrationConnection.java

 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glancing over this code I see two possible corrections:
1) In UserRegisterClient, close the connection after you're done with it.
2) In UserRegistrationConnection, don't start the thread if an exception occurs. Move line 40 to after line 25.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great! I am on my way to correct them. Thanks a lot for helping me Rob Spoor, I really appreciate your help.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic