Re: tcp connection in gui: event based



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.
.



Relevant Pages

  • Re: Problem with OnReceive method
    ... > I' m developing a multithread application with a socket network ... > continuosly Receive in the thread socket loop. ... > this one start the server thread. ... when a connection arrived it start a new childthread and ...
    (microsoft.public.vc.mfc)
  • Re: Using too many threads?
    ... - Only the main window thread may update the main window GUI. ... Only the details window thread may update the details GUI. ... Is it safe for multiple threads to be reading/writing the same socket? ... "connection controller" thread per connection: ...
    (comp.os.os2.programmer.misc)
  • Re: GNAT.Sockets. Blocking?
    ... some servers to prevent robot or programs ... request some browsers information or they close the connection. ... end loop ... I'm kind of new to socket programming and I need some help here. ...
    (comp.lang.ada)
  • Re: TCP Sockets errors
    ... connected socket?", you'd put the read code, GetString, and Invoke in a loop ... to the outer loop waiting for another connection. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Clarification please
    ... Sorry writing the last post i did figure out the answer, in my loop as i ... read the string i escape the loop on reading a 0, ... > connection, send data, close the socket and repeat. ...
    (microsoft.public.win32.programmer.networks)