
10/05/2009, 21:44
|
| | Fecha de Ingreso: mayo-2009
Mensajes: 6
Antigüedad: 15 años, 10 meses Puntos: 0 | |
Respuesta: duda con sockets y threads hola cucuru:
Lo de la imagen ya lo pude resolver,pero a lo q aun nole hallo es a lo de los threads, te pongo el codigo de mi servidor y le me mi cliente para q les heches un ojo y me digas q se le podria hacer.
El cliente es el siguiente:
import java.io.*;
import java.security.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;
class recibe extends JFrame {
public static void main(String[] args) {
ServerSocket serverSocket = null;
Socket cliente = null;
Object pub = null;
Rpizarra llego =null;
ObjectInputStream in= null;
String resultado="";
try {
serverSocket = new ServerSocket(5000);
} catch (Exception e){
System.err.println("No se puede escuchar en puerto:20002.");
System.exit(1);
}
while(true){
try {
cliente = serverSocket.accept();
in= new ObjectInputStream(cliente.getInputStream());
System.out.println("conectado");
llego = new Rpizarra();
} catch (Exception e){
System.err.println("no acepta conexion");
}
try {
while(true){
llego.escribe((String)in.readObject());
/*pub = (Object)in.readObject();
if(pub instanceof Polygon){
Polygon p = (Polygon)pub;
llego.dibuja(p);
} else {
Color c = (Color) pub;
llego.otroColor(c);
}*/
}
} catch (Exception e){
System.err.println("fin conexion");
llego.dispose();
}
}
}
}
El Servidor es el siguiente:
import java.io.*;
import java.net.*;
import java.security.*;
import java.awt.*;
class trans extends Frame {
static ObjectOutputStream out;
public static void main(String[] args) {
Socket echoSocket = null;
try {
echoSocket = new Socket(args[0],5000);
System.out.println("conectado");
out= new ObjectOutputStream(echoSocket.getOutputStream());
pizarra ob=new pizarra();
} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
}
}
public static void fin(){
try {
out.close();
} catch (Exception e) {};
System.exit(0);
}
} |