Ciao a tutti, mi sono appena iscritto al forum per un problema che non sono riuscito a risolvere nemmeno googlando alla ricerca di situazioni simili. Ho trovato qualche thread in questo stesso forum ma purtroppo non sono stati utili a risolvere il mio caso.
Sto lavorando a un progetto, nel quale un client ad un certo punto entra in un ciclo infinito, all'interno del quale ogni tot secondi manda una richiesta (per il rinnovo della sua autenticazione ad una rete, ma non è importante) ad un server.
Il fatto è che il processo funziona, ma dopo qualche scambio (ovviamente il server risponde al client in caso di rinnovo positivo o negativo) il server si ferma in attesa sull'ObjectInputStream, come se il client non mandasse nulla, mentre invece il client manda tutto come sempre...
Di seguito posto il codice delle parti salienti:
Ringrazio anticipatamente per l'aiuto, dato che non so più dove sbattere la testa.codice:SERVER: try{ Socket serviceSocket=new Socket(); serviceSocket.setReuseAddress(true); serviceSocket=serverSocket.accept(); mainHandler.log("request from "+serviceSocket); while(!exit){ mainHandler.log("receiving logout or renew"); isLogout=networkHandler.receiveRenewLogout(serviceSocket); if(isLogout==1){ [...] if(isLoggedOut){ [...] exit=true; } [...] } } }catch (IOException ex){ex.printStackTrace();} public int receiveRenewLogout(Socket socket){ try { serviceOis = new ObjectInputStream(socket.getInputStream()); infoClient = (ExchangeObject) serviceOis.readObject(); if (!infoClient.isLogin()){ serverThread.updateClientStatus(infoClient); return 1; } else if(infoClient.isRenew()){ return 0; } } catch (IOException ex1) {ex1.printStackTrace();} catch(ClassNotFoundException ex2){ex2.printStackTrace();} return -1; } CLIENT: nel ciclo infinito viene chiamata questa funzione public void sendRenewLogout(String staticKey, Socket s, String what){ try{ interaction.log("renewing..."); ExchangeObject exchangeObj=new ExchangeObject(); if(what.compareTo("logout")==0){ exchangeObj.setLogin(false); } else if(what.compareTo("renew")==0){ exchangeObj.setRenew(true); } exchangeObj.setStaticHash(staticKey); ObjectOutputStream serviceOos = new ObjectOutputStream(s.getOutputStream()); serviceOos.reset(); serviceOos.writeObject(exchangeObj); serviceOos.flush(); }catch(IOException ex){ex.printStackTrace();} }

Rispondi quotando