programming chat: get the messages back

Discussion in 'Java' started by wanderin, Apr 7, 2005.

  1. wanderin

    wanderin Guest

    I try to program a chat, and I can send the message to the server.
    But, unfortunately, my server can't send back the message it received.
    Althought I put the necessary code, I think:

    try{
    BufferedReader recep = new BufferedReader(
    new
    InputStreamReader(SOCK.getInputStream()));

    while (true){
    String message = recep.readLine();
    OUT_BUF.println(message);
    }
    }

    I notify the OUT_BUF parameter refers to the PrintWriter class.
    As you can see, the message received should be returned to the
    clients.

    Thank you for helping.
    wanderin, Apr 7, 2005
    #1
    1. Advertising

  2. wanderin

    kjc Guest

    wanderin wrote:
    > I try to program a chat, and I can send the message to the server.
    > But, unfortunately, my server can't send back the message it received.
    > Althought I put the necessary code, I think:
    >
    > try{
    > BufferedReader recep = new BufferedReader(
    > new
    > InputStreamReader(SOCK.getInputStream()));
    >
    > while (true){
    > String message = recep.readLine();
    > OUT_BUF.println(message);
    > }
    > }
    >
    > I notify the OUT_BUF parameter refers to the PrintWriter class.
    > As you can see, the message received should be returned to the
    > clients.
    >
    > Thank you for helping.

    Try sending the flush message to the output stream
    kjc, Apr 7, 2005
    #2
    1. Advertising

  3. wanderin

    wanderin Guest

    kjc <> wrote in message news:<vxh5e.14311$>...
    > wanderin wrote:
    > > I try to program a chat, and I can send the message to the server.
    > > But, unfortunately, my server can't send back the message it received.
    > > Althought I put the necessary code, I think:
    > >
    > > try{
    > > BufferedReader recep = new BufferedReader(
    > > new
    > > InputStreamReader(SOCK.getInputStream()));
    > >
    > > while (true){
    > > String message = recep.readLine();
    > > OUT_BUF.println(message);
    > > }
    > > }
    > >
    > > I notify the OUT_BUF parameter refers to the PrintWriter class.
    > > As you can see, the message received should be returned to the
    > > clients.
    > >
    > > Thank you for helping.

    > Try sending the flush message to the output stream


    I tried to give the flush() method, but it still doen't work. In fact,
    I think the problem is my server program doesn't know where to send
    the messages in its buffer. So, I have to tell him that by a method
    such as a kind of:
    send(new Socket(ip_to_send, port_of_ip_client));

    As I want there are more than one client, I should create a public
    method, called in the thread of my reading/sending messages.
    wanderin, Apr 8, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DazedAndConfused
    Replies:
    0
    Views:
    325
    DazedAndConfused
    Sep 13, 2005
  2. Replies:
    0
    Views:
    347
  3. Replies:
    0
    Views:
    2,190
  4. Jaspreet
    Replies:
    0
    Views:
    683
    Jaspreet
    Sep 18, 2004
  5. Sean
    Replies:
    1
    Views:
    431
Loading...

Share This Page