Re: Desperately need help in Tcl socket and fileevent puzzle...

From: Donal K. Fellows (donal.k.fellows_at_man.ac.uk)
Date: 08/19/04


Date: Thu, 19 Aug 2004 11:11:57 +0100

Mike wrote:
> I have a small program in TCL that:
> 1) connect to a socket
> 2) setup a fileevent handler to read binary data coming from this
> socket

Did you remember to put:
   fconfigure $channel -translation binary
in there? Without that, it won't work.

> When binary data received
> 2a) The handler does: set binStream [read $channel]
> 2a) the handler then appends this "binStream" to a file:
> puts -nonewline $binFile $binStream

You'll want to also make the $binFile channel a binary channel.

> Looking at the content of the binary file logged in (2a), the content
> was 100% correct. However, the proc that processes the data (4) got
> corrupted data from time to time from the result of "binary scan" when
> it parsed "binStreamCopy".

Ah, let me guess. You're running on Windows? Or possibly OSX?

The problem is end-of-line translation, and putting in suitable
[fconfigure] invokations (see above for an example) will fix it (and a
few other things that you've luckily not hit so far). If you're
processing the data in a command written in C, there are a few other
issues you might want to bear in mind, but you don't seem to be
indicating that that's the case here.

Donal.



Relevant Pages

  • Read/write binary data
    ... Does anyone have an example of how to read binary data from a channel and write the data to another channel using a fixed buffer size? ... Using fconfigure with -buffersize, -translation, -encoding, etc but still not working right. ...
    (comp.lang.tcl)
  • Re: threaded tcl crash
    ... This a VERY generic problem with the channel ... The driver needs to know of a cut and splice. ... When a file event happens on the socket, the driver needs to alert the ... notifier thread datum for me either (WSAAsyncSelect's hwnd param determines ...
    (comp.lang.tcl)
  • Re: TCL multiple sockets communication
    ... can anybody tell me if it is possible for a server to open ... puts "Accepted connection $channel from $client" ... easily modify it to accept multiple ports by adding another [socket ... proc accept {srv channel client port} { ...
    (comp.lang.tcl)
  • Re: Control flow design question
    ... As it turns out, I CAN use a different IP/Port for each socket, so I ... transmitted back to the appropriate channel terminals). ... and appends each request to its channel's queue. ... Each queue's requests are processed by one dedicated worker ...
    (comp.lang.java.programmer)
  • Re: UCX and dangling sockets
    ... >> It usually occurs when attempting to start a Roboeda listener on port ... >> A TCPIP SHO DEVICE does not show any socket attached to the affected ... >when there is an OpenVMS channel with a socket on it (the UCB could also ... Hopefully you won't have a bizillion mbufs ...
    (comp.os.vms)