you are viewing a single comment's thread.

view the rest of the comments →

[–]iDontShift 3 insightful - 1 fun3 insightful - 0 fun4 insightful - 1 fun -  (2 children)

great resource. anyone that programs that wants to do this .. having a full working structure build from is nice.

I wandered away from C mostly, but wanted to share my new love TCL .. this is echo server written in TCL .. it handles almost all the internal socket stuff.

great language for personal hobby programming. also can handle serious work. computation is not good. creating a ui is easy

proc Echo_Server {port} {
    set s [socket -server EchoAccept $port]
    vwait forever
}
proc EchoAccept {sock addr port} {
    global echo
    puts "Accept $sock from $addr port $port"
    set echo(addr,$sock) [list $addr $port]
    fconfigure $sock -buffering line
    fileevent $sock readable [list Echo $sock]
}

proc Echo {sock} {
    global echo
    if {[eof $sock] || [catch {gets $sock line}]} {
    close $sock
    puts "Close $echo(addr,$sock)"
    unset echo(addr,$sock)
    } else {
        puts $sock $line
    }
}

#
# A client of the echo service.
#

proc Echo_Client {host port} {
    set s [socket $host $port]
    fconfigure $s -buffering line
    return $s
}

# A sample client session looks like this
#   set s [Echo_Client localhost 2540]
#   puts $s "Hello!"
#   gets $s line

http://www.tcl.tk/about/netserver.txt

[–]fschmidt 2 insightful - 1 fun2 insightful - 0 fun3 insightful - 1 fun -  (1 child)

I strongly agree with the Tcl philosophy which modern scum naturally reject.

[–]iDontShift 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (0 children)

and the world makes sense again ; )