From: Hrachya.Aghajanyan on 7 Jan 2010 01:18 Hi, I wrote a simple send-receive mechanism for binary .tar.gz files over socket. Client on Unix sends the file and the server on Windows receives the file . When I run it, somehow the received file is much smaller than the original file sent from the client. Could you please see my code below and tell me if there's special handling necessary for .tar.gz files ? Thank you! ......... ........... # Connects to the server if { [catch {set s [socket 10.10.0.165 2112]} err]} { puts "ERROR: Failed to connect to the server (10.10.0.165): $err" return } # Control the way file I/O is done using channel fconfigure $s -buffering line puts $s $p_layer puts $s $t_figure ..... ..... ################################################ # Sending binary layers.tar.gz from client ################################################ set size [file size layers.tar.gz] set in0 [open layers.tar.gz] fconfigure $in0 -translation binary -buffersize 50000 fconfigure $s -translation binary -buffersize 50000 puts $s [list layers.tar.gz $size] fcopy $in0 $s -size $size flush $s close $in0 # Wait for the complete file transfer after 10000 close $s } ############################################ # Receiving layers.tar.gz on server ############################################ fconfigure $sock -translation binary -buffersize 50000 gets $sock line foreach {name size} $line {} puts "$sock $port: Getting layer files from client" set out0 [open $elib0/layers.tar.gz w] fconfigure $out0 -translation binary -buffersize 50000 fcopy $sock $out0 -size $size close $out0 delay close $sock }
From: Hrachya.Aghajanyan on 7 Jan 2010 02:53 On Jan 7, 10:18 am, "Hrachya.Aghajan...(a)gmail.com" <hrachya.aghajan...(a)gmail.com> wrote: > Hi, > > I wrote a simple send-receive mechanism for binary .tar.gz files over > socket. Client on Unix sends the file and the server on Windows > receives the file . When I run it, somehow the received file is much > smaller than the original file sent from the client. > > Could you please see my code below and tell me if there's special > handling necessary for .tar.gz files ? Thank you! > > ......... > ........... > # Connects to the server > if { [catch {set s [socket 10.10.0.165 2112]} err]} { > puts "ERROR: Failed to connect to the server (10.10.0.165): > $err" > return > } > > # Control the way file I/O is done using channel > fconfigure $s -buffering line > > puts $s $p_layer > puts $s $t_figure > ..... > ..... > ################################################ > # Sending binary layers.tar.gz from client > ################################################ > set size [file size layers.tar.gz] > set in0 [open layers.tar.gz] > fconfigure $in0 -translation binary -buffersize 50000 > > fconfigure $s -translation binary -buffersize 50000 > puts $s [list layers.tar.gz $size] > fcopy $in0 $s -size $size > flush $s > close $in0 > > # Wait for the complete file transfer > after 10000 > > close $s > > } > > ############################################ > # Receiving layers.tar.gz on server > ############################################ > fconfigure $sock -translation binary -buffersize 50000 > gets $sock line > foreach {name size} $line {} > puts "$sock $port: Getting layer files from client" > > set out0 [open $elib0/layers.tar.gz w] > > fconfigure $out0 -translation binary -buffersize 50000 > fcopy $sock $out0 -size $size > close $out0 > delay > close $sock > > > > } I guess I found the error :) The doc says "When reading binary information from a channel only read should be used." Thanks! H.
From: Uwe Klein on 7 Jan 2010 03:01 Hrachya.Aghajanyan(a)gmail.com wrote: > Hi, > > I wrote a simple send-receive mechanism for binary .tar.gz files over > socket. Client on Unix sends the file and the server on Windows > receives the file . When I run it, somehow the received file is much > smaller than the original file sent from the client. > > Could you please see my code below and tell me if there's special > handling necessary for .tar.gz files ? Thank you! > > > ......... > ........... > # Connects to the server > if { [catch {set s [socket 10.10.0.165 2112]} err]} { > puts "ERROR: Failed to connect to the server (10.10.0.165): > $err" > return > } > > # Control the way file I/O is done using channel # I would leave the buffering as is. # fconfigure $s -buffering line > puts $s $p_layer ;# what's in these two variables? > puts $s $t_figure > ..... > ..... > ################################################ > # Sending binary layers.tar.gz from client > ################################################ > set size [file size layers.tar.gz] puts stderr size:$size > set in0 [open layers.tar.gz] fconfigure $in0 -translation binary ;# -buffersize 50000 > fconfigure $s -translation binary ;# -buffersize 50000 > puts $s [list layers.tar.gz $size] set sendbytes [ fcopy $in0 $s -size $size ] puts stderr sent:$sendbytes > flush $s > close $in0 > > # Wait for the complete file transfer # should be complete ( fcopy blocks until finished ), you don't need this # after 10000 > > close $s > } > > > ############################################ > # Receiving layers.tar.gz on server > ############################################ > fconfigure $sock -translation binary -buffersize 50000 > gets $sock line > foreach {name size} $line {} > puts "$sock $port: Getting layer files from client" > > set out0 [open $elib0/layers.tar.gz w] > > fconfigure $out0 -translation binary ;# -buffersize 50000 set received [ fcopy $sock $out0 -size $size ] puts stderr received:$received > close $out0 > delay > close $sock > > } try the changes. compare the three debug messages? uwe
From: Gerald W. Lester on 7 Jan 2010 11:52 Hrachya.Aghajanyan(a)gmail.com wrote: > On Jan 7, 10:18 am, "Hrachya.Aghajan...(a)gmail.com" > <hrachya.aghajan...(a)gmail.com> wrote: >> Hi, >> >> I wrote a simple send-receive mechanism for binary .tar.gz files over >> socket. Client on Unix sends the file and the server on Windows >> receives the file . When I run it, somehow the received file is much >> smaller than the original file sent from the client. >> >> Could you please see my code below and tell me if there's special >> handling necessary for .tar.gz files ? Thank you! >> >> ......... >> ........... >> # Connects to the server >> if { [catch {set s [socket 10.10.0.165 2112]} err]} { >> puts "ERROR: Failed to connect to the server (10.10.0.165): >> $err" >> return >> } >> >> # Control the way file I/O is done using channel >> fconfigure $s -buffering line >> >> puts $s $p_layer >> puts $s $t_figure >> ..... >> ..... >> ################################################ >> # Sending binary layers.tar.gz from client >> ################################################ >> set size [file size layers.tar.gz] >> set in0 [open layers.tar.gz] >> fconfigure $in0 -translation binary -buffersize 50000 >> >> fconfigure $s -translation binary -buffersize 50000 >> puts $s [list layers.tar.gz $size] >> fcopy $in0 $s -size $size >> flush $s >> close $in0 >> >> # Wait for the complete file transfer >> after 10000 >> >> close $s >> >> } >> >> ############################################ >> # Receiving layers.tar.gz on server >> ############################################ >> fconfigure $sock -translation binary -buffersize 50000 >> gets $sock line >> foreach {name size} $line {} >> puts "$sock $port: Getting layer files from client" >> >> set out0 [open $elib0/layers.tar.gz w] >> >> fconfigure $out0 -translation binary -buffersize 50000 >> fcopy $sock $out0 -size $size >> close $out0 >> delay >> close $sock >> >> >> >> } > > I guess I found the error :) The doc says "When reading binary > information from a channel only read should be used." Also, you should do the puts of the size before reconfiguring the channel as binary -- or better yet change your protocol to something where the first record has a header of a known length and that record contains the file name and size. Then switch to copy mode. -- +------------------------------------------------------------------------+ | Gerald W. Lester | |"The man who fights for his ideals is the man who is alive." - Cervantes| +------------------------------------------------------------------------+
From: Hrachya.Aghajanyan on 9 Jan 2010 01:07 On Jan 7, 12:01 pm, Uwe Klein <uwe_klein_habertw...(a)t-online.de> wrote: > Hrachya.Aghajan...(a)gmail.com wrote: > > Hi, > > > I wrote a simple send-receive mechanism for binary .tar.gz files over > > socket. Client on Unix sends the file and the server on Windows > > receives the file . When I run it, somehow the received file is much > > smaller than the original file sent from the client. > > > Could you please see my code below and tell me if there's special > > handling necessary for .tar.gz files ? Thank you! > > > ......... > > ........... > > # Connects to the server > > if { [catch {set s [socket 10.10.0.165 2112]} err]} { > > puts "ERROR: Failed to connect to the server (10.10.0.165): > > $err" > > return > > } > > > # Control the way file I/O is done using channel > > # I would leave the buffering as is. > # fconfigure $s -buffering line > > puts $s $p_layer ;# what's in these two variables?> puts $s $t_figure > > ..... > > ..... > > ################################################ > > # Sending binary layers.tar.gz from client > > ################################################ > > set size [file size layers.tar.gz] > > puts stderr size:$size> set in0 [open layers.tar.gz] > > fconfigure $in0 -translation binary ;# -buffersize 50000 > > fconfigure $s -translation binary ;# -buffersize 50000> puts $s [list layers.tar.gz $size] > > set sendbytes [ fcopy $in0 $s -size $size ] > puts stderr sent:$sendbytes > > > flush $s > > close $in0 > > > # Wait for the complete file transfer > > # should be complete ( fcopy blocks until finished ), you don't need this > # after 10000 > > > > > > > close $s > > } > > > ############################################ > > # Receiving layers.tar.gz on server > > ############################################ > > fconfigure $sock -translation binary -buffersize 50000 > > gets $sock line > > foreach {name size} $line {} > > puts "$sock $port: Getting layer files from client" > > > set out0 [open $elib0/layers.tar.gz w] > > > fconfigure $out0 -translation binary ;# -buffersize 50000 > > set received [ fcopy $sock $out0 -size $size ] > puts stderr received:$received > > > close $out0 > > delay > > close $sock > > > } > > try the changes. > compare the three debug messages? > > uwe Thanks Uwe for the proposed changes! I did as you said herein but I still get a file 519 bytes in size instead of 119 KBytes that were originally sent from the client side. BTW, the command read $sock did not help either . It simply does not transfer a single bit over .
|
Next
|
Last
Pages: 1 2 3 Prev: Very very very new for tcl/tk Next: keyword highlight in text widget |