Perchè questi semplici programmi non funzionano ??? Sto impazzendo!!
codice:public class prova { ServerSocket ss; Socket s=null; PrintStream ps = null; public prova() throws IOException { try { ss = new ServerSocket(9996); Socket s1 = ss.accept(); s = s1; System.out.println(s); ps = new PrintStream(s.getOutputStream()); // STREAM PER L'INVIO while (s.isConnected()){ ps.print("ciao prova1"); } } catch (IOException ex) { Logger.getLogger(prova.class.getName()).log(Level.SEVERE, null, ex); } } public static void main(String Args[]) throws IOException { new prova(); } }Il messaggio inviato da prova non arriva!!codice:public class prova1 { BufferedReader br = null; Socket s=null; public prova1() throws IOException, ClassNotFoundException { s = new Socket("localhost", 9996); System.out.println(s); br = new BufferedReader(new InputStreamReader(s.getInputStream())); // STREAM PER LA RICEZIONE ricezioneStringhe(); } public void ricezioneStringhe() // RICEZIONE STRINGHE { String line; System.out.println("# Processo di ricezione avviato"); // try { while (s.isConnected()) { line = br.readLine(); while (line != null) { System.out.println(line); line = br.readLine(); }} } catch (IOException ex) { System.out.println("# Impossibile ricevere dati dal client."); } } public static void main(String Args[]) throws IOException, ClassNotFoundException { new prova1(); } }

Rispondi quotando