Results 1 to 4 of 4
  1. #1
    program is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default Sending and recieving information from a server simultaneously

    I'm trying to design a chat client that will be able to send messages to a server and receive messages simultaneously. Here is pseudo-code for what I have so far:

    while(true){
    System.out.print("What do you want to write to the server?:");
    userInput = reader.readLine(); //line 3
    writeToServer(userInput);

    messagesFromServer = getServerMessages;
    System.out.println("Server: "+messagesFromServer);
    }

    My problem is that my program will pause and wait for user input at line 3, and therefore messages from the server will not continuously stream in. My question: how can I design my chat client so that messages from the server are still displayed even when the program is waiting for user input?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Sending and recieving information from a server simultaneously

    Using separate threads comes immediately to mind.

  3. #3
    program is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default Re: Sending and recieving information from a server simultaneously

    Thanks for the reply. I'll read up on using separate threads in java

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Sending and recieving information from a server simultaneously

    Quote Originally Posted by program View Post
    Thanks for the reply. I'll read up on using separate threads in java
    You won't be sorry that you did. There are several tutorials about sending info via sockets that demonstrate how to do this using separate threads, and Google will help you find them. Best of luck.

Similar Threads

  1. sending and recieving files
    By rav in forum New To Java
    Replies: 9
    Last Post: 07-26-2010, 04:34 PM
  2. [SOLVED] Show Server and execution environment information
    By mtyoung in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 02-04-2009, 05:22 AM
  3. Sending a Vector to TCP server
    By eva in forum Networking
    Replies: 1
    Last Post: 01-02-2008, 10:34 AM
  4. Kwok Information Server 2.6.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-13-2007, 05:16 PM
  5. Kwok Information Server 2.3
    By levent in forum Java Software
    Replies: 0
    Last Post: 07-26-2007, 08:05 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
  •