Cita:
package server;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
private ServerSocket sv;
private Socket s;
private ObjectOutputStream os;
private ObjectInputStream oi;
public Server() {
try {
System.out.println("Server oN");
sv = new ServerSocket(2001);
s = sv.accept();
os = new ObjectOutputStream(s.getOutputStream());
oi =new ObjectInputStream(s.getInputStream());
os.writeUTF("HOLA CLIENTE");
System.out.println(oi.readUTF());
os.close();
s.close();
sv.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println("ERROR");
}
}
public static void main(String args[]) {
new Server();
}
}
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
private ServerSocket sv;
private Socket s;
private ObjectOutputStream os;
private ObjectInputStream oi;
public Server() {
try {
System.out.println("Server oN");
sv = new ServerSocket(2001);
s = sv.accept();
os = new ObjectOutputStream(s.getOutputStream());
oi =new ObjectInputStream(s.getInputStream());
os.writeUTF("HOLA CLIENTE");
System.out.println(oi.readUTF());
os.close();
s.close();
sv.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println("ERROR");
}
}
public static void main(String args[]) {
new Server();
}
}
Mi idea es que se pueda conectar un cliente a traves de telnet .Pero al conectarse y querer enviar un dato, el server me tira el siguiente error:
Cita:
Server oN
java.io.StreamCorruptedException: invalid stream header: 0D0A6473
ERROR
at java.io.ObjectInputStream.readStreamHeader(ObjectI nputStream.java:800)
at java.io.ObjectInputStream.<init>(ObjectInputStream .java:297)
at server.Server.<init>(Server.java:22)
at server.Server.main(Server.java:41)
java.io.StreamCorruptedException: invalid stream header: 0D0A6473
ERROR
at java.io.ObjectInputStream.readStreamHeader(ObjectI nputStream.java:800)
at java.io.ObjectInputStream.<init>(ObjectInputStream .java:297)
at server.Server.<init>(Server.java:22)
at server.Server.main(Server.java:41)
a que se debe??