Java - TCP

 
Vista:

TCP

Publicado por Nora (1 intervención) el 28/06/2005 05:22:06
como hago para enviar una matriz desde el servidor al cliente, yo tengo en el servidor:
import java.net.*;
import java.io.*;
public class Servidor extends Thread{
ServerSocket s = null;
public Servidor() {
try {
s = new ServerSocket(5432);
}
catch (IOException e) {
}
}
public void enviar(int ma[][], int i, int j){

try {
Socket s1 = s.accept();
OutputStream s1out = s1.getOutputStream();
DataOutputStream dos = new DataOutputStream(s1out);
System.out.println(ma);
dos.writeInt(i);
dos.writeInt(j);
for(int f=0;f<i;f++)
for(int c=0;c<j;c++)
dos.write(ma[f][c]);
dos.flush();
dos.close();
s1.close();
}
catch (IOException e) {
}
}

}
y en el cliente:
import java.io.*;
import java.net.*;
public class Cliente extends Thread {
int ma[][],i,j;
Socket s1;
public Cliente(String ip) {
try {
s1 = new Socket(ip, 5432);
}
catch (ConnectException connExc) {
System.err.println("Could not connect to the server.");
}
catch (IOException e) {
// ignore
}
}
public void recibir(){
try {
InputStream is = s1.getInputStream();
DataInputStream dis = new DataInputStream(is);
i=dis.readInt();
j=dis.readInt();
for(int f=0;f<i;f++){
for(int c=0;c<j;c++){
ma[f][c]=dis.read();
System.out.print(ma[f][c]);
}
System.out.println();
}
dis.close();
s1.close();
}
catch (ConnectException connExc) {
System.err.println("Could not connect to the server.");
}
catch (IOException e) {
// ignore
}
}
public void run(){
while(true){
recibir();
}
}

}
pero me sale un error justo cuando está recibiendo la matriz, porfa ayudenme :(
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder