I'm trying to create a multiplayer game, who runs on the internet. The problem is that I'm trying to get input on a stream and for some reason I can't make 2 streams with one socket, and I'll explain:
Socket s=new Socket("127.0.0.1",5001);
ObjectInputStream obj1=new ObjectInputStream(s.getInputStream());
ObjectInputStream obj2=new ObjectInputStream(s.getInputStream());
Can someone explain me why this code snippet isn't working?
Edit: Here's another example for code sample that isn't working.
while (true) {
try {
objI = new ObjectInputStream(sock.getInputStream());
objO = new ObjectOutputStream(sock.getOutputStream());
}catch(Exception e) {
e.printStackTrace();
}
}
Edit 2: thanks very much for answering. I tried to flush the objects, but I keep getting this error:
java.io.StreamCorruptedException: invalid stream header: 33740003
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at Proccess.run(Proccess.java:22)
at java.lang.Thread.run(Unknown Source)