🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
2 messages
2 total messages Started by Alejandro Guzman Wed, 23 Oct 2002 13:42
Problem receiving data with a socket client
#789
Author: Alejandro Guzman
Date: Wed, 23 Oct 2002 13:42
58 lines
3120 bytes
Hello everyone,  I�m trying to do a socket client application with Jbuilder 6, this app send information to a server  socket (made in Delphi 6), I  don�t have problem sending the information, my problem is receiving the information, because I don�t receive the information, unless  I turn off the server socket, and in this moment I receive the information�. I don�t know what wrong, I did several examples that I found on the internet and all of them give me the same problem�. The following is the source code:

import java.net.*;
import java.io.*;
import java.util.*;

public class Socket_OnLine {
  public static void main(String[] args)
    {
      String Servidor         = "SERVER_NAME";
      int    Puerto           =  1024;
      String mensajeEncrip    = "";
      String mensajeRespuesta = "";
      String respuestaSocket;

      try
        {
          System.out.println("Connecting to " + Servidor + " Port " + Puerto);

          // Abrimos un Socket conectado al servidor y al puerto
          Socket socket = new Socket(Servidor, Puerto);

          // Conseguimos el canal de entrada
          BufferedReader entrada = new BufferedReader(new InputStreamReader(socket.getInputStream()));

         // Conseguimos el canal de salida
          BufferedWriter salida = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

          mensajeEncrip = "TO8000000007AT00001T";
          salida.write(mensajeEncrip.trim());
          salida.flush();

          // Recogemos la l�nea devuelta por el servidor y la presentamos en la pantalla

//***** THE APPLICATION FREEZE IN THIS LINE *****//              
          mensajeRespuesta = entrada.readLine();

          System.out.println(mensajeRespuesta);

          // Cerramos el Socket
          salida.close();
          entrada.close();
         socket.close();
        }
      catch (UnknownHostException e)
        {
          System.out.println("Entro a la exception de UnknownHostException "+e.getMessage());
        }
      catch (IOException e)
        {
          System.out.println("Entro a la exception de IOException "+e.getMessage());
        }
    }
}

Does any body can help me please�..

Alejandro
Re: Problem receiving data with a socket client
#790
Author: Owen Green
Date: Wed, 23 Oct 2002 14:50
29 lines
2192 bytes
"Alejandro Guzman" <aeguzmanv@hotmail.com> wrote in message
news:3db6a742$1@newsgroups.borland.com...
>
> Hello everyone,  I'm trying to do a socket client application with
Jbuilder 6, this app send information to a server  socket (made in
Delphi 6), I  don't have problem sending the information, my problem is
receiving the information, because I don't receive the information,
unless  I turn off the server socket, and in this moment I receive the
information.. I don't know what wrong, I did several examples that I
found on the internet and all of them give me the same problem.. The
following is the source code:
>

<snip>

> //***** THE APPLICATION FREEZE IN THIS LINE *****//
>           mensajeRespuesta = entrada.readLine();

    Perhaps the data sent from the server isn't terminated with an EOL
marker (say '\n', or #10 in Delphi speak). This will cause readLine to
block until it hits the end of the stream (i.e. it disconnects).

Try running some tests without the buffered reader (i.e. using the plain
input stream) to examine what data /is/ available, and whether it has a
line terminator.

hth
Owen
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads