CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2010

    Applet-Servlet Communication EOFException

    Hi! ive been searching and searching through forums because it seems this problem is very common, but none of the solutions ive seen so far suits me, so im here looking for some help because ive been stuck one week with this. First of all sorry if my english isnt the best... im a bit rusty...

    Well, i had some code that worked perfectly, but i needed to perform some changes because i needed the servlet to send more info to the applet, and here started the problems, when i made the changes it started to throw EOFException when i was trying to read the InputStream, and furthermore when i came back to the original code it started to throw the exception in the same place too :banghead:

    So here i am... dont know what to do now and i entrust to you to give me some tips.

    Here comes some code.

        	public ListasComponentesSeleccionables cargarListasComponentes( ) throws IOException, ClassNotFoundException {
    		String serv = "/Desaladora/cargarListasComponentesApplet.do";
    		String host = Principal.documentBase.getHost( );
    		URL direccion = new URL( "http", host, 8080, serv );
    		// Create conection
    		URLConnection connection = direccion.openConnection( );
    		connection.setDoInput( true );  
    		connection.setDoOutput( true ); 
    		connection.setUseCaches( false ); 
    		connection.setRequestProperty( "Content-Type", "application/x-java-serialized-object" );
    		ObjectOutputStream output;
    		output = new ObjectOutputStream( connection.getOutputStream( ) );
    		output.writeObject( new Boolean(true) );
    		output.flush( );
    		output.close( );
    		ObjectInputStream input = new ObjectInputStream( connection.getInputStream( ) ); //<-- Here is the problem
    		ListasComponentesSeleccionables response = new ListasComponentesSeleccionables( );
    		response = ( ListasComponentesSeleccionables ) input.readObject( );
    		return response;
    public class CargarListasComponentesAppletAction extends Action {
    public ActionForward execute(	ActionMapping mapping,
    			                             	ActionForm form,
    			                             	HttpServletRequest request,
    			                             	HttpServletResponse response ) throws ServletException, IOException, Exception  {
    		InitialContext context = new InitialContext();
    		SensorManagerService sensor_service;
    		ActuatorManagerService actuator_service;
    		Globals.LOGGER_SECURITY.debug( "Entering ACTION 'CargarListasComponentesAppletAction'" );
    			ObjectInputStream bufferentrada = new ObjectInputStream(request.getInputStream());
    			Boolean peticionOK = (Boolean)bufferentrada.readObject();
    			ObjectOutputStream buffersalida = new ObjectOutputStream(response.getOutputStream());
    			sensor_service = ( SensorManagerService ) context.lookup( "desaladora/SensorManagerServiceBean/local" );
    			ArrayList<AlarmConnectedSensorDTO> sensorList = sensor_service.findAllSensorsToAlarms();
    			actuator_service = ( ActuatorManagerService ) context.lookup( "desaladora/ActuatorManagerServiceBean/local" );
    			ArrayList<AlarmConnectedActuatorDTO> actuatorList = actuator_service.findAllActuatorsToAlarms();
    			buffersalida.writeObject( crearListasSeleccionables(sensorList, actuatorList) );
    		catch(Exception e)
    			System.out.println("Error en la trasmision de datos");
    		return null;
    	private ListasComponentesSeleccionables crearListasSeleccionables(ArrayList<AlarmConnectedSensorDTO> sensorList, ArrayList<AlarmConnectedActuatorDTO> actuatorList) {
    		Vector<Integer> vectorSensores = new Vector<Integer>();
    		Vector<Integer> vectorActuadores = new Vector<Integer>();
    		for(AlarmConnectedSensorDTO sensor : sensorList) {
    			vectorSensores.add(sensor.getIdSensor( ));
    		for(AlarmConnectedActuatorDTO actuator : actuatorList) {
    			vectorActuadores.add(actuator.getIdActuator( ));
    		ListasComponentesSeleccionables listasComponentesSeleccionables = new ListasComponentesSeleccionables(vectorSensores, vectorActuadores);
    		return listasComponentesSeleccionables;

    Thank you for your time

  2. #2
    Join Date
    Apr 2010

    Re: Applet-Servlet Communication EOFException

    ive been running some test in another computer, and that code simply works, but it doesnt work in the machine i usually work.

    Maybe someway the stream get corrupt? the info ive been trying to send and started throwing the exception may still be in the stream? I dont know what to think right now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)