Java Networking Program

Get help on programming - C++, Java, Delphi, etc.
Post Reply
ckritntt
Registered User
Posts: 28
Joined: 04 Jun 2004, 02:00

Java Networking Program

Post by ckritntt »

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?
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

Unfortunately i'm not that far up the java knowledge tree.

But try the Api
Image

MAY THE CHEESE BE WITH YOU!
{PK} Law
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Post by RuadRauFlessa »

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.
ckritntt
Registered User
Posts: 28
Joined: 04 Jun 2004, 02:00

Post by ckritntt »

Thanx for the replies!
How would I go about the second option RuadRauFlessa?My lecturer basically said I should do it the way you described in the first paragraph,but that seems like it could get quite complex.
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Post by RuadRauFlessa »

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.
ckritntt
Registered User
Posts: 28
Joined: 04 Jun 2004, 02:00

Post by ckritntt »

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?
AngryRabbit
Registered User
Posts: 988
Joined: 24 Feb 2003, 02:00
Location: Warner Beach, Natal

Post by AngryRabbit »

What are you studying ckritntt?
Image
ckritntt
Registered User
Posts: 28
Joined: 04 Jun 2004, 02:00

Post by ckritntt »

Doing ndip I.T. But i'm just trying this as a sideline project
Post Reply