Results 1 to 10 of 10
  1. #1
    ersachinjain is offline Member
    Join Date
    Aug 2009
    Posts
    51
    Rep Power
    0

    Default Problem on server side (Socket Programming)

    Hi

    I have a very weird problem. My application is a client server application and the server is running on a Unix machine ij the background using no-hup command. The problem is that after some days of running in this case it is like 15 days there is no response form the server. i can not find the problem so I am posting a certain section of my code here. if any one can find any technical flaw in the code plz do let me know. i would really appreciate that.


    Here is the Code:




    import java.io.*;
    import java.net.*;
    import java.sql.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;


    public class Server
    {
    public static void main(String[] args)
    {
    ServerSocket s;

    try
    {
    s = new ServerSocket(7000);
    System.out.println("Server started");

    while(true)
    {
    Socket incoming = s.accept( );
    System.out.println("incoming " + incoming);
    ThreadedDataObjectHandler t = new ThreadedDataObjectHandler(incoming);
    t.start();
    }
    }
    catch (Exception e)
    {

    }
    }

    static class ThreadedDataObjectHandler extends Thread
    {
    public ThreadedDataObjectHandler()
    {

    }

    public ThreadedDataObjectHandler(Socket i)
    {
    incoming = i;
    }

    public void run()
    {
    try
    {
    //System.out.println("Server testing ");

    //System.out.println("incoming " + incoming);

    in = new ObjectInputStream(incoming.getInputStream());
    out = new ObjectOutputStream(incoming.getOutputStream());

    //System.out.println("in " + in);
    //System.out.println("out " + out);

    String strpassword = "";

    ExtartingSurgeData extdata = null;

    float []stationslevel = new float[6];

    DataObject myobjecttowrite = new DataObject();

    while(true)
    {
    // something //
    }


    Thanks

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    First of all please use code tags when you posting again. Unformated codes are harder to read. If you don't know how to do it, please check on my forum signature, you can find a relevant page.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Regarding your question, better to add some exception handling code in catch block. It's the easiest way to track what's really happening.

  4. #4
    ersachinjain is offline Member
    Join Date
    Aug 2009
    Posts
    51
    Rep Power
    0

    Default

    Alright I will post the thread again with proper tagged code:



    Hi

    I have a very weird problem. My application is a client server application and the server is running on a Unix machine ij the background using no-hup command. The problem is that after some days of running in this case it is like 15 days there is no response form the server. i can not find the problem so I am posting a certain section of my code here. if any one can find any technical flaw in the code plz do let me know. i would really appreciate that.


    Here is the Code:




    import java.io.*;
    import java.net.*;
    import java.sql.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;


    public class Server
    {
    public static void main(String[] args)
    {
    ServerSocket s;

    try
    {
    s = new ServerSocket(7000);
    System.out.println("Server started");

    while(true)
    {
    Socket incoming = s.accept( );
    System.out.println("incoming " + incoming);
    ThreadedDataObjectHandler t =
    new ThreadedDataObjectHandler(incoming);
    t.start();
    }
    }
    catch (Exception e)
    {

    }
    }

    static class ThreadedDataObjectHandler extends Thread
    {
    public ThreadedDataObjectHandler()
    {

    }

    public ThreadedDataObjectHandler(Socket i)
    {
    incoming = i;
    }

    public void run()
    {
    try
    {
    in = new ObjectInputStream(incoming.getInputStream());
    out = new ObjectOutputStream(incoming.getOutputStream());

    DataObject myobjecttowrite = new DataObject();

    while(true)
    {
    // do something //
    }
    .................................................. ..................

    Thanks

  5. #5
    ersachinjain is offline Member
    Join Date
    Aug 2009
    Posts
    51
    Rep Power
    0

    Default

    Thanks

    The problem occurs only say after 15 days. So could this be coz the program goes into an infinite loop, coz there are 2 while loops

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by ersachinjain View Post
    Thanks

    The problem occurs only say after 15 days. So could this be coz the program goes into an infinite loop, coz there are 2 while loops
    Could be something like this. For a long run, may be because of some hardware issues or anything related the socket can be not listening.

  8. #8
    ersachinjain is offline Member
    Join Date
    Aug 2009
    Posts
    51
    Rep Power
    0

    Default

    Oh so you mean there can be hardware issues because of which socket has problem in listening. Could this be because the server on which the code is running is really old like 10 years old.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    That's not the exact issue lol. I just give you an example. Many issues could be cause for that, and what I want to point to you is that log more information on relevant catch blocks. Then it's easy to track the issues, if any.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by ersachinjain View Post
    Could this be because the server on which the code is running is really old like 10 years old.
    In an endless loop, if you are not handle the exceptions properly it can be executed even for millions of years. :)

Similar Threads

  1. Replies: 1
    Last Post: 03-20-2010, 07:03 PM
  2. NIO Server: listening on client's side socket
    By carek in forum Networking
    Replies: 1
    Last Post: 12-24-2009, 07:30 AM
  3. [SOLVED] Problem with socket programming(Vista)
    By jagatsastry in forum Networking
    Replies: 1
    Last Post: 02-02-2009, 03:56 PM
  4. Client Server socket problem - help needed
    By kellaw in forum Threads and Synchronization
    Replies: 6
    Last Post: 10-03-2008, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •