Re: transferring large amounts of data



The read() call on the receiving side can use a buffer of arbitrary
length- you might just have to call read() more often if you use a very
small buffer.
Note that the read() call will most probably NOT fill a 1-Mbyte buffer,
but will return after reading less data. So you have to interpret the
return value of your InputStream.read() call ! (If you know that there
is a 1Mbyte chunk coming, you have to call read() in a loop until all
data is read.
The following piece of code might help you:
public static void readCompleteBlocking(InputStream is,byte[] target)
throws IOException
{
int readBytes=0;
while(readBytes<target.length){
int read=is.read(target,readBytes,target.length-readBytes);
if(read<1)throw new IOException("read() returned 0 or
negative");
readBytes+=read;
}
}

.



Relevant Pages

  • Re: Two macros for resource management
    ... > PUSH(fclose(source)) ... > PUSH(fclose(target)) ... > PUSH(free(buffer)) ... {int result = EXIT_FAILURE; ...
    (comp.lang.c)
  • Re: [PATCH] Fix user data corrupted by old value return of sysctl
    ... by sysctl syscall, this call probably corrupts the user data right after the old value buffer, the issue lies in sysctl_string seting 0 to oldval, len is the available buffer size specified by the user, obviously, this will write to the first byte of the user memory place immediate after the old value buffer, the correct way is that sysctl_string doesn't set 0, the user should do it by self in the program. ... int sysctl{struct __sysctl_args args ... int target; ... Current host name: ...
    (Linux-Kernel)
  • Re: pushing the envelope with sockets
    ... receiving on the socket they are received (upto the buffer size), you can even change what happens if the buffer runs full. ... int read = S.EndReceive; ... class AsyncReader: Reader ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Fundamentals question, is this how it works?
    ... Note the packet may be partially received when you get ... That is what i thought i was saying that it receives it all in a stream ... receving the buffer size each time. ... receiving that many bytes i then break and wait for the next set of data ...
    (microsoft.public.win32.programmer.networks)
  • Re: CAsyncSocket and Send
    ... I'm also sending/receivingbinary data (file transfer). ... which usually is less than a full buffer). ... >> Are you using TCP/IP or UDP? ... >>>in C and the receiving side is MFC. ...
    (microsoft.public.vc.mfc)