in reply to Re^2: sysread and syswrite in tcp sockets
in thread sysread and syswrite in tcp sockets
thanks for all the inputs. my client and server are actually running on different machine.
from the input given by you all, i figured that my problem is because sysread uses partial read. thus when i send a big file size, it will partial read it. thus on my client side i have to buffer it myself so as to append the partial data together to form back the single file.
thus i make sure of select with timeout to help me in this. below is my working code, hope it will helps anyone who encounter this problem. once again, thanks for the help!
#sysread uses partial read, so a stream of file might be break down in +to 2-3 chunks #thus use select to establish a timeout, if there is an interval of 1 +sec or more where no data #coming in, then it is sate to say there will be a new data stream, as + my data is coming in interval of fixed n secs. while(1){ $len = 0; do{ $offset = 0; if(defined $buffer){ $offset = length($buffer); } $temp = sysread($sock, $buffer, 500000000, $offset); $len += $temp; #append data together if they come in back to back } while ($select -> can_read(1)); #if > 1 sec without any data coming in, quit createFile(<filename>, $buffer, $len, 0); #processFile();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: sysread and syswrite in tcp sockets
by ikegami (Patriarch) on Dec 23, 2008 at 06:23 UTC | |
|
Re^4: sysread and syswrite in tcp sockets
by gone2015 (Deacon) on Dec 23, 2008 at 20:38 UTC | |
by Anonymous Monk on Dec 26, 2008 at 05:02 UTC | |
by gone2015 (Deacon) on Dec 28, 2008 at 01:01 UTC | |
by Anonymous Monk on Jan 06, 2009 at 06:11 UTC | |
by BrowserUk (Patriarch) on Jan 06, 2009 at 06:40 UTC | |
by gone2015 (Deacon) on Jan 06, 2009 at 10:47 UTC | |
|