Re: tcp connection in gui: event based
- From: claird@xxxxxxxxx (Cameron Laird)
- Date: Fri, 17 Oct 2008 13:23:41 +0000
In article <2114c037-2704-47d3-826a-e43779639d82@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
schlenk <schlenk@xxxxxxxxxxxxxxxx> wrote:
On Oct 17, 11:41 am, toby...@xxxxxxxxxxxxxxxx wrote:.
.
.
.I have two applications which I would like to communicate via a socket
connection. Actually one is in Perl, but to solve the problem at Tcl
level would would suffice for me. Main application is a GUI at server
side which should simply read messages and add them to a listbox. All
.
.
you don't need a read data loop or threads for this. Tcl provides you.
with the fileevent mechanism which integrates very nicely with sockets
and Tk GUIs.
The basic mechanism is:
1. Open a server [socket]
2. Write a small proc that does the accept and sets the connection to
nonblocking
3. Use [fileevent] to register procs that get fired when the socket is
readable/writable
4. Inside the fileevent proc read the data from the socket (but don't
use any loop, a single read is good enough)
5. Check if you have a full line read
6. If you have a full line, send it to the GUI, maybe dispatching via
after to not block the event loop if its a bit bigger
.
.
Michael is perhaps too polite to make explicit that not
only do you not need a read data loop or threads, but
they would make for strictly inferior solutions. Code
up Michael's outline: that's the right approach.
Incidentally, this program--a simple GUI monitor which
displays messages received from clients--has been written
before, multiple times. Its existence proof has several
examples.
.
- References:
- tcp connection in gui: event based
- From: tobyboy
- Re: tcp connection in gui: event based
- From: tobyboy
- Re: tcp connection in gui: event based
- From: tobyboy
- Re: tcp connection in gui: event based
- From: schlenk
- tcp connection in gui: event based
- Prev by Date: Re: tcl 8.5 and community package compatibility testing
- Next by Date: Re: tcl 8.4 support
- Previous by thread: Re: tcp connection in gui: event based
- Next by thread: Re: tcp connection in gui: event based
- Index(es):
Relevant Pages
|