This is the mail archive of the
xconq7@sources.redhat.com
mailing list for the Xconq project.
Re: How to fix the xconq network code
- From: lduperval at microcelli5 dot com
- To: bboett at adlp dot org
- Cc: XConq Mailing List <xconq7 at sources dot redhat dot com>
- Date: Mon, 11 Feb 2002 11:32:21 -0500 (EST)
- Subject: Re: How to fix the xconq network code
On 11 Feb, Bruno Boettcher wrote:
> On Mon, Feb 11, 2002 at 07:33:48AM -0500, lduperval@microcelli5.com wrote:
>> Wel, as long as you're rewriting the code, you could rewrite it in Tcl and
> uhm what's so great about tcl (besides beeing a new language to learn)?
>
Plenty, but in this case, the socket code can be much shorter to write and
maintain than a C version. Here is a simple server:
#!/bin/sh
# \
exec tclsh "$0" "$@"
proc serveConnection {Handle} {
set LineLength [gets $Handle Line]
if {$LineLength>=0} {
#This is where you finally can do something with the data.
#We simply put it back where it came from.
puts $Handle "Received: $Line"; flush $Handle
} elseif {[eof $Handle]} {
catch {close $Handle}
}
}
proc acceptConnections {ConnectionFileHandle ClientAddress ClientPort} {
fconfigure $ConnectionFileHandle -blocking 0
fileevent $ConnectionFileHandle readable [list \
catch [list serveConnection $ConnectionFileHandle]]
}
socket -server acceptConnections 2000
vwait Dummyvariable
And a sample client:
#!/bin/sh
# \
exec tclsh "$0" "$@"
set Handle [socket localhost 2000]
puts -nonewline $Handle "Hello"; flush $Handle
puts $Handle " Dolly"; flush $Handle
puts [gets $Handle]
close $Handle
I know some of the client (GUI) code is already written in tcl. It can
possibly be integrated there (for Unix, anyway -- I'm not sure whre the Tcl
code is used).
If you define the proper protocol, though, it could be used anywhere. But
then, you *do* have dependency on Tcl on all platforms -- I'm not sure that
is currently the case.
Disclaimer: I'm a Tcl advocate.
L
--
Laurent Duperval <mailto:lduperval@microcelli5.com>
Les lapins doivent fourmiller ici comme les idées dans la tête du chef! De
quoi mourir de faim!
-Kid Ordinn