Hi!
I'm busy writing a program that will allow me to send a file from one pc to another via client-server using the java stream classes(ObjectOuputStream etc.).But when I try to read a gif with the ObjectInputStream it says "Invalid Stream Header" in the console window.Is there anyone who knows how I can get around this problem?
Java Networking Program
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
It might help to know exactly what you are writing to the stream inthe first place. You say you copy a file over the network via an ObjectOutputStream. Is it then safe to presume that you are encapsulating the data contained within the file inside an object which you then write to the stream.
There is another way you could get around it but it requires you to use another type of i/o stream and no object encapsulation of the data.
There is another way you could get around it but it requires you to use another type of i/o stream and no object encapsulation of the data.
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
Actually it is quite simple did it once for a project. All you need do is read the data from the file and write it directly to the stream onto the network and the other end should read the raw data again and write it to a temporary file. From there on you can use the temp file for data. And try to work as much as possible without encapsulating your stream into more and more stream handlers since it will slow things down. The only one you can encapsulate your streams with are the Buffered streams which would the reading and writing actually alot faster.
Thanx for the advice.But i'm still abit lost.I've attached some of the client - code :
client = new Socket("localhost",8200);
output = new ObjectOutputStream(client.getOutputStream());
input = new ObjectInputStream( new FileInputStream("image001.gif"));
String s = (String)input.readObject();
System.out.println("Image read");
output.writeObject(s);
output.flush();
output.close();
This is the code I use to send the "image data" through to the server.Where and how do you think I should add the buffer?
client = new Socket("localhost",8200);
output = new ObjectOutputStream(client.getOutputStream());
input = new ObjectInputStream( new FileInputStream("image001.gif"));
String s = (String)input.readObject();
System.out.println("Image read");
output.writeObject(s);
output.flush();
output.close();
This is the code I use to send the "image data" through to the server.Where and how do you think I should add the buffer?
-
- Registered User
- Posts: 988
- Joined: 24 Feb 2003, 02:00
- Location: Warner Beach, Natal