ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I basically have a TCP client\server where the server sends a big file to the client chunk by chunk. I basically want to ask how is it possible to write to an output file a byte array each time a chunk is received.
An example can be:
Quote:
public class Chunk implements Serializable
{
private byte [] data;
// getters and setters
}
Thanks for your reply. I do not really know on how much I can use a FileOutputStream to write to the file. For instance, I might receive chunks in a random order. I had a thought about FileOutputStream but I am not 100% sure if write(byte[], int, int) will necessarily work. Do you believe that write(byte[], int, int) will necessarily work?
Once more again thanks for your interest. I would really like to ask you that because I do not have so much experience with TCP sockets programming. Setting the case that a TCP client\server will communicate with the use of Object Messages rather than sending data through a byte stream what I would like to know if there is message delivery guarantee, and if there is any need for acknoledging Object Messages. Therefore, is every message guaranteed to be received. Will Java retransmit itself corrupted messages?
I don't know what 'Object Messages' are, but I can tell you what TCP is: full-duplex reliable bytestream between two parties (actually, it is two independent bytestreams). The bytes arrive in the order they were sent (no loss, no duplication, no reorder), but message boundaries aren't reserved.
Actually, there's no messages, only byte-streams: the remote side will receive every byte in the same order you sent them, but not neccessarily in one part: it might first receive one byte, then 30000 bytes, then 767 bytes... (Of course, the connection still might get lost during the transfer.)
I actually used the FileOutputStream that you told me and I can successfully send and write to disk some files. The only that really bothers me is if I try to write a bad chunk (a message altered due to communication problems) to the FileOutputStream I do not really believe that I can overwrite the chunk. The FileOutputStream I think only supports continuous writes of bytes. Do you really know any possible way to specify a method like
Quote:
write(byte [] data, int streamStartOffset)
This should actually write the data starting at specified streamStartOffset. So if I have a file of 1024 bytes, write(data, 0) will indicate that the data will be written starting from index 0.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.