ho creato questa applicazione: invio una stringa dalclient e il server la visualizza.
il server è in run e termina subito senza errore. cosa non va???
CLIENT
package clienttcp;
import java.io.*;
import java.net.*;
import java.util.*;
/**
*
* @author Auron
*/
public class clientTCP {
private String host;
private String info;
private Socket client;
/** Creates a new instance of clientTCP */
public clientTCP() {
host="localhost";
info="hello world...";
try{
dialogo();
}
catch(IOException ioEx){
System.out.println("Errore: " + ioEx.getMessage());
}
}
private void dialogo()throws java.io.IOException{
client=new Socket(host, 4413);
client.setSoTimeout(20000);
PrintStream out=new PrintStream(client.getOutputStream());
out.print(info);
client.close();
}
}
SERVER
package servertcp;
import java.io.*;
import java.net.*;
import java.util.*;
/**
*
* @author Auron
*/
public class serverTCP extends Thread{
private ServerSocket server;
/** Creates a new instance of serverTCP */
public serverTCP() {
super();
try{
server=new ServerSocket(4413);
System.out.println("server in ascolto...");
}
catch(IOException ioEx){
System.out.println("Errore server: " + ioEx.getMessage());
System.exit(1);
}
}
public void run(){
Socket client=null;
while(true){
if(server==null)
return;
try{
client=server.accept();
BufferedReader in=new BufferedReader(new InputStreamReader(client.getInputStream()));
boolean fine=false;
while(fine){
String line=in.readLine();
if(line!=null)
System.out.println(line);
else
fine=true;
}
in.close();
client.close();
}
catch(IOException ioEx){
System.out.println("Errore 2 su Server:" + ioEx.getMessage());
System.exit(1);
}
}
}
}
HELLLLLPPPPPPP!!!!!!!!