Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - errore java.net.SocketException: Connection reset
Forum - Java - errore java.net.SocketException: Connection reset

Avatar
thebonni90 (Normal User)
Rookie


Messaggi: 22
Iscritto: 01/01/2011

Segnala al moderatore
Postato alle 21:35
Domenica, 05/06/2011
Salve ragazzi
ho fatto un semplice programmino formato da server e client dove il server gestisce le risorse invece il
client richiede le risorse però ho la seguente ecc ...
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.io.ObjectInputStream$PeekInputStream.peek(Unknown Source)
    at java.io.ObjectInputStream$BlockDataInputStream.peek(Unknown Source)
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at contSkel.run(contSkel.java:35)
codice dello skeleton con anche il protocollo

Codice sorgente - presumibilmente Java

  1. /* SKELETON
  2.  * Protocolllo
  3.  * RICHISTA                                                             RISPOSTA
  4.  *  "RIC" <Integer>     --------------> <risorsa>|<giaAssegnata>|<InterruptedException>
  5.  *      "RIL" <Integer><risorsa> -------->      "OK"|<risorsaErrata>|<NoRisorsa>
  6.  *      la NPE sarà lo stab a sollevarla
  7.  */
  8. import java.io.IOException;
  9. import java.io.ObjectInputStream;
  10. import java.io.ObjectOutputStream;
  11. import java.net.Socket;
  12.  
  13.  
  14. public class contSkel extends Thread{
  15.         //CAMPI
  16.         private Socket s;
  17.         private ObjectInputStream in;
  18.         private ObjectOutputStream out;
  19.         private GestoreImpl gest;
  20.         //COSTRUTTORE
  21.         public contSkel(Socket s,GestoreImpl gest)throws NullPointerException,IOException{
  22.                 if(s==null||gest==null)throw new NullPointerException();
  23.                         this.s=s;
  24.                         this.gest=gest;
  25.                         //Apriamo i 2 stream
  26.                         out= new ObjectOutputStream(s.getOutputStream());
  27.                         in = new ObjectInputStream(s.getInputStream());
  28.         }
  29.         //METODI
  30.         public void run(){
  31.                 try{
  32.                         String op;
  33.                         while(true){//ciclo infinito
  34.                                 //leggo una stringa dello stream
  35.                                  op =(String)in.readObject();
  36.                                  if(op.equals("RIC")){
  37.                                          int tmp = ((Integer)in.readObject()).intValue();
  38.                                          try{
  39.                                                  Risorsa ris1= gest.richiedi(tmp);
  40.                                                  out.writeObject(ris1);
  41.                                          }catch(giaAssegnata e){out.writeObject(e);}
  42.                                          catch(InterruptedException e){out.writeObject(e);}
  43.                                         }
  44.                                  else
  45.                                  {
  46.                                          //allora è un rilascia
  47.                                        
  48.                                                 int tmp = ((Integer)in.readObject()).intValue();
  49.                                                 Risorsa tmpris= (Risorsa)in.readObject();
  50.                                                 try{
  51.                                                 gest.rilascia(tmp, tmpris);
  52.                                                 }catch(risorsaErrata e){out.writeObject(e);}
  53.                                                  catch(NoRisorsa e){out.writeObject(e);}
  54.                                  }
  55.                         }//end while
  56.                         //end primo try                
  57.                 }catch(IOException e){e.printStackTrace();}
  58.                  catch(ClassNotFoundException e){e.printStackTrace();}
  59.                 finally{
  60.                         try{
  61.                                 s.close();
  62.                         }catch(IOException e){;}
  63.                 }
  64.                
  65.         }
  66. }



codeice dello stub
Codice sorgente - presumibilmente Java

  1. /*
  2.  * Protocolllo
  3.  * RICHISTA                                                             RISPOSTA
  4.  *  "RIC" <Integer>     --------------> <risorsa>|<giaAssegnata>|<InterruptedException>
  5.  *      "RIL" <Integer><risorsa> -------->      "OK"|<risorsaErrata>|<NoRisorsa>
  6.  *      la NPE sarà lo stab a sollevarla
  7.  */
  8.  
  9. import java.io.IOException;
  10. import java.io.ObjectInputStream;
  11. import java.io.ObjectOutputStream;
  12. import java.net.InetAddress;
  13. import java.net.Socket;
  14.  
  15.  
  16. public class gestoreStub implements GestoreRisorse {
  17.         //CAMPI
  18.         private Socket s;
  19.         private ObjectOutputStream out;
  20.         private ObjectInputStream in;
  21.         //COSTRUTTORE
  22.         public gestoreStub()throws IOException{
  23.                 InetAddress a = InetAddress.getByName(null);
  24.                 s= new Socket (a,11112);
  25.                 out = new ObjectOutputStream (s.getOutputStream());
  26.                 in= new ObjectInputStream (s.getInputStream());
  27.         }
  28.         //METODI
  29.        
  30.         public Risorsa richiedi(int u) throws giaAssegnata, InterruptedException,
  31.                         IOException {
  32.                 Object tmp = null;
  33.                 out.writeObject("RIC");
  34.                 out.writeObject(new Integer (u));
  35.                 try{
  36.                         tmp= in.readObject();
  37.                 }catch(ClassNotFoundException e){throw new IOException();}//sic nel protocollo non è previsto
  38.                 if(tmp instanceof giaAssegnata)throw new giaAssegnata();
  39.                 else if(tmp instanceof InterruptedException )throw (InterruptedException )tmp;//cast e poi rialzo eccezione
  40.                 else return (Risorsa)tmp;//ritorna la risorsa
  41.         }
  42.  
  43.         public void rilascia(int u, Risorsa r) throws risorsaErrata, NoRisorsa,
  44.                         NullPointerException, IOException {
  45.                 Object tmp;
  46.                 if(r==null)throw new NullPointerException();
  47.                 out.writeObject("RIL");
  48.                 out.writeObject(new Integer(u));
  49.                 out.writeObject(r);
  50.                 try{
  51.                         tmp = in.readObject();
  52.                 }catch(ClassNotFoundException e){throw new IOException();//sic non è previsto nel protocollo
  53.                 }
  54.                 if(tmp instanceof risorsaErrata)throw (risorsaErrata)tmp;
  55.                 else if(tmp instanceof NoRisorsa)throw (NoRisorsa)tmp;
  56.                 else return;
  57.         }
  58. }//end class



grazie a tt:D:D:D
se serve alleggo tutto il codice intero8-)8-)8-)

PM Quote