• 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

how can i solve this problem

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i write a application which create a ServerSocket listening the port 888 just as following,and i want the listening action is performed for ever.

ServerSocket soServer=null;
try
{
soServer = new ServerSocket(8888);
}
catch(IOException e)
{
System.out.println("Creating ServerSocket Error...");
System.out.println(e.toString());
}
Socket client=null;
while (true)
{
try
{
client = soServer.accept ();
}
catch(IOException e)
{}
SmsClient echo = new SmsClient(client);
//SmsClient extends thread
echo.start ();
}

but the next day, i find the application has stoped for some reason,can you help me and give me some clues ?
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What clues do you have? Here's some wild guesses that I can think of:
ServerSocket.accept() threw something other than IOException (like a Runtime or Error) ?
A client connected to port 8888 and sent some data that caused your SMSClient constructor to throw an exception ?
SMSClient or some other Thread called System.exit ?
The JVM ran out of memory (OutOfMemoryError or something like that) ?
Hotspot crashed and you got a huge thread dump ?
Someone logged onto your machine and send a SIGKILL to the JVM process ?

For something like this, if you really want it to be more robust you are going to have to catch more general exceptions (like Throwable) and at least call printStackTrace or something. The place where you have
catch (IOException e) { }
is most unhelpful when something goes wrong. If you do this then at least you will have some clues as to why it dies.
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic