Sockets java NO ROUTE TO HOST
Publicado por Albert (1 intervención) el 18/02/2009 17:52:05
Buenas estamos dando los sockets en java, con el codigo que adjunto consigo conectarme a mi mismo, en cambio si pongo la ip de otro pc (red lan) me da el problema no route to host. Alguien sabe como solucionarlo??
Los pings responden en ambos lados.
CLIENTE
import java.io.DataInputStream;
import java.io.InputStream;
import java.net.Socket;
class Cliente {
static final String HOST ="192.168.2.235";
static final int PORT=8081;
public Cliente() {
try{
Socket skCliente = new Socket(HOST,PORT);
InputStream aux = skCliente.getInputStream();
DataInputStream flujo = new DataInputStream( aux );
System.out.println( flujo.readUTF() );
skCliente.close();
} catch( Exception e ) {
System.out.println( e.getMessage() );
}
}
public static void main( String[] arg ) {
new Cliente();
}
}
SERVIDOR
import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
class Servidor {
static final int PORT=8081;
public Servidor() {
try {
ServerSocket skServidor = new ServerSocket( PORT );
System.out.println("Escolto el port " + PORT );
for ( int numCli = 0; numCli < 3; numCli++) {
Socket skCliente = skServidor.accept(); // Crea objecte
System.out.println("Serveixo al client " + numCli);
OutputStream aux = skCliente.getOutputStream();
DataOutputStream flujo= new DataOutputStream( aux );
flujo.writeUTF( "Hola client " + numCli );
skCliente.close();
}
System.out.println("Masses clients per avui");
} catch( Exception e ) {
System.out.println( e.getMessage() );
}
}
public static void main( String[] arg ) {
new Servidor();
}
}
GRACIAAAAAAAAAAAAAAAAAAAAS!!
Los pings responden en ambos lados.
CLIENTE
import java.io.DataInputStream;
import java.io.InputStream;
import java.net.Socket;
class Cliente {
static final String HOST ="192.168.2.235";
static final int PORT=8081;
public Cliente() {
try{
Socket skCliente = new Socket(HOST,PORT);
InputStream aux = skCliente.getInputStream();
DataInputStream flujo = new DataInputStream( aux );
System.out.println( flujo.readUTF() );
skCliente.close();
} catch( Exception e ) {
System.out.println( e.getMessage() );
}
}
public static void main( String[] arg ) {
new Cliente();
}
}
SERVIDOR
import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
class Servidor {
static final int PORT=8081;
public Servidor() {
try {
ServerSocket skServidor = new ServerSocket( PORT );
System.out.println("Escolto el port " + PORT );
for ( int numCli = 0; numCli < 3; numCli++) {
Socket skCliente = skServidor.accept(); // Crea objecte
System.out.println("Serveixo al client " + numCli);
OutputStream aux = skCliente.getOutputStream();
DataOutputStream flujo= new DataOutputStream( aux );
flujo.writeUTF( "Hola client " + numCli );
skCliente.close();
}
System.out.println("Masses clients per avui");
} catch( Exception e ) {
System.out.println( e.getMessage() );
}
}
public static void main( String[] arg ) {
new Servidor();
}
}
GRACIAAAAAAAAAAAAAAAAAAAAS!!
Valora esta pregunta


0