3 Replies Latest reply: Mar 26, 2007 7:30 PM by EJP RSS

    problem in reading from the socket

    807597
      Hi all,
      My server application is in c++ and client application is in java.
      In my client application,when i am using InputStream.read(byte[] b),it is working fine.But if I use BufferedReader(new InputStreamReader(new InputStream)).readLine(),it is not receiving any data.The client application is keep on waiting and not giving any data.I am not understanding the reason.
      Please express your views.

      with regards,
      ajse
        • 1. Re: problem in reading from the socket
          807597
          Hi

          Hi all,
          My server application is in c++ and client application is in java.
          In my client application,when i am using InputStream.read(byte[] b),it is working fine.

          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
          But if I use BufferedReader(new InputStreamReader(new InputStream)).readLine(),it is not receiving any data.
          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
          Instead of new BufferedReader (new InputStreamReader (new InputStream())).readLine ();

          You should be using
          new BufferedReader (new InputStreamReader (socket.getInputStream()())).readLine ();
          Where scoket represents open socket to your server.
          =======================================================
          The client application is keep on waiting and not giving any data.I am not understanding the reason.

          Please express your views.

          with regards,
          ajse

          HTH
          VJ
          • 2. Re: problem in reading from the socket
            807597
            Hi,
            Does your server append a new line charecter at the end of response. Coz the readLine() method will wait till it gets a "\n" to print the charecter. So there is a possibility it waits while reading and your connection gets timed out
            • 3. Re: problem in reading from the socket
              EJP
              Also contrary to reply #1 you should create the BufferedReader once, rather than creating a new one for every read, otherwise the buffered data in the previous one will be lost, and you will block forever waiting for something you've already received.