alessiop86
alessiop86

Reputation: 1305

Store a file inside an object

I have a Java client/server desktop application, where the communication between client and server is based on Sockets, and the messages exchanged between client and server are serialized objects (message objects, that incapsulate requests and responses).

Now I need to make the client able to upload a file from the local computer to the server, but I can't send the File through the buffer, since the Buffer is already used for exchanging the message objects.

Should i open another stream to send the file, or is there any better way to upload a file for my situation?

Upvotes: 0

Views: 102

Answers (3)

David Soroko
David Soroko

Reputation: 9086

You can keep your solution and pass the file content as an object, for example as a String - use Base64 encoding (or similar) of the content if it contains troublesome characters

Upvotes: 1

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33534

I need to make the client able to upload a file from the local computer to the server

- Open a Solely Dedicated Connection to the Server for File uploading.

- Use File Transfer Protocol to ease your work, and moreover its quite easy and reliable to use the Apache's common lib for File uploading and downloading....

See this link:

http://commons.apache.org/net/

Upvotes: 1

Claudiu
Claudiu

Reputation: 229361

You really only have two options:

  1. Open another connection dedicated to the file upload and send it through that.
  2. Make a message object representing bits of a file being uploaded, and send the file in chunks via these message objects.

The former seems simpler & cleaner to me, requiring less overhead and less complicated code.

Upvotes: 1

Related Questions