From: Debby Luebke on
hi Tcl-ers:

i have a problem reading binary files from channel on the host
computer.

host computer info is as follows: MS Win 2003 server with SP2 and Tcl
8.5.7.0

i gave a thorough read to article at http://wiki.tcl.tk/1180 . i
follow all the rules explained but no file gets thru .

# Setter
proc set_file { file sock } {
set size [file size $file]
fconfigure $sock -translation binary
set fid [open "$file" r]
fconfigure $fid -translation binary
set data [read $fid $size]
puts $sock $size
puts -nonewline $sock $data
close $fiid
}

# Getter
proc read_file { sock sender_ip sender_port } {
fconfigure $sock -translation binary
gets $sock size
set data [read $sock $size]
set fid [open "file.zip" w]
fconfigure $fid -translation binary
puts -nonewline $fid $data
close $fid
}

please help.
D.
From: Alexandre Ferrieux on
On Jan 16, 4:36 pm, Debby Luebke <debby.lue...(a)gmail.com> wrote:
> hi Tcl-ers:
>
> i have a problem  reading binary files from channel on the host
> computer.
>
> host computer info is as follows: MS Win 2003 server with SP2 and Tcl
> 8.5.7.0
>
> i gave a thorough read to article athttp://wiki.tcl.tk/1180. i
> follow all the rules explained but no file gets thru .
>
> # Setter
> proc set_file { file sock } {
>     set size [file size $file]
>     fconfigure $sock -translation binary
>     set fid [open "$file" r]
>     fconfigure $fid -translation binary
>     set data [read $fid $size]
>     puts $sock $size
>     puts -nonewline $sock $data
>     close $fiid
>
> }
>
> # Getter
> proc read_file { sock sender_ip sender_port } {
>     fconfigure $sock -translation binary
>     gets $sock size
>     set data [read $sock $size]
>     set fid [open "file.zip" w]
>     fconfigure $fid -translation binary
>     puts -nonewline $fid $data
>     close $fid
>
> }
>
> please help.
> D.

Hint 1: define "nothing gets thru" : does execution reach the end of
both functions ? (use puts stderr to see progression)

Hint 2: give the whole program, not just the two functions above.

Hint 3: since network transmission is involved, take a wireshark/
tcpdump trace (filtered with "tcp.port==...") to get an external view
of the problem.

-Alex
From: Gerald W. Lester on
Debby Luebke wrote:
> hi Tcl-ers:
>
> i have a problem reading binary files from channel on the host
> computer.
>
> host computer info is as follows: MS Win 2003 server with SP2 and Tcl
> 8.5.7.0
>
> i gave a thorough read to article at http://wiki.tcl.tk/1180 . i
> follow all the rules explained but no file gets thru .
>
> # Setter
> proc set_file { file sock } {
> set size [file size $file]
> fconfigure $sock -translation binary
> set fid [open "$file" r]
> fconfigure $fid -translation binary
> set data [read $fid $size]
> puts $sock $size
> puts -nonewline $sock $data
> close $fiid
> }
>
> # Getter
> proc read_file { sock sender_ip sender_port } {
> fconfigure $sock -translation binary
> gets $sock size
> set data [read $sock $size]
> set fid [open "file.zip" w]
> fconfigure $fid -translation binary
> puts -nonewline $fid $data
> close $fid
> }

1) with binary files do not use gets use read
2) you need to set the socket blocking in "set_file"


--
+------------------------------------------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
From: Debby Luebke on
On Jan 16, 11:14 pm, "Gerald W. Lester" <Gerald.Les...(a)cox.net> wrote:
> Debby Luebke wrote:
> > hi Tcl-ers:
>
> > i have a problem  reading binary files from channel on the host
> > computer.
>
> > host computer info is as follows: MS Win 2003 server with SP2 and Tcl
> > 8.5.7.0
>
> > i gave a thorough read to article athttp://wiki.tcl.tk/1180. i
> > follow all the rules explained but no file gets thru .
>
> > # Setter
> > proc set_file { file sock } {
> >     set size [file size $file]
> >     fconfigure $sock -translation binary
> >     set fid [open "$file" r]
> >     fconfigure $fid -translation binary
> >     set data [read $fid $size]
> >     puts $sock $size
> >     puts -nonewline $sock $data
> >     close $fiid
> > }
>
> > # Getter
> > proc read_file { sock sender_ip sender_port } {
> >     fconfigure $sock -translation binary
> >     gets $sock size
> >     set data [read $sock $size]
> >     set fid [open "file.zip" w]
> >     fconfigure $fid -translation binary
> >     puts -nonewline $fid $data
> >     close $fid
> > }
>

thank you for your comments.

> 1) with binary files do not use gets use read
i do gets of size in code to specify how many bytes will be read and
returned:

gets $sock size
set data [read $sock $size]

i tried to put all stuff in header and scan length as you suggested in
a neighbor thread to a collegue but then i get only size and no file
contents at the host end. can't figure out why. puts do not help
either , execution reaches end with no problem.

> 2) you need to set the socket blocking in "set_file"
thanks, will try blocking -none
>
> --
> +------------------------------------------------------------------------+
> | Gerald W. Lester                                                       |
> |"The man who fights for his ideals is the man who is alive." - Cervantes|
> +------------------------------------------------------------------------+

From: Alexandre Ferrieux on
On Jan 16, 8:14 pm, "Gerald W. Lester" <Gerald.Les...(a)cox.net> wrote:
>
> 1) with binary files do not use gets use read

No. Here it's a mixed text-binary protocol: length sent first as a
line, then data.
Gets is perfectly adapted to this use.


> 2) you need to set the socket blocking in "set_file"

Default being blocking mode, what do you want to add ?

-Alex