How to get the user input while server is waiting for client's message


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: How to get the user input while server is waiting for client's message

  1. #1
    Join Date
    Oct 2003
    Posts
    4

    How to get the user input while server is waiting for client's message

    I have a server/client program (using sockets)
    I used a thread to let a server always waiting for client's request, but how should I found that

    there is no message pass to server from client.
    Code:
    public void run(){
    while (true){
    
    Socket server = serverP.accept();
    ObjectInputStream inFromClient = new ObjectInputStream(server.getInputStream());
    inMessage = (Message)inFromClient.readObject();
    
    .........
    .......
    ..........
    
    System.out.println("Deadlock may occurred, please enter your command: ");
    BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
    String command = inFromUser.readLine();
    .......
    }
    The server is waiting for the inMessage that is passed from multiple clients. But if the server

    received no message after some time, it will assume something is wrong (eg, there is a

    deadlock), then it will ask the user to input the command to execute the method.

    If I put
    Code:
    "System.out.println("Do you want to take Snapshot: ");
    BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
    String command = inFromUser.readLine();"
    inside the while loop, it will keep asking user to enter the input when every time the client

    connect to the server. But I want to ask the user to enter the command only when the server

    can't get the response from clients.

    How should I do?
    Please help.

    [ArchAngel added CODE tags]

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    If you look at the Socket class you will find that you can set them up so they will timeout if there is no activity. Place your message there.
    ArchAngel.
    O:-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center