docs: Remove docs for the case command
[jimtcl.git] / examples / unix.dgram.server
blob43ada19e31f1d76fe0e74d21290e8c9738fc3d5d
1 # Example of a udp server which sends a response
3 # Listen on port 20000. No host specified means 0.0.0.0
4 file delete unix.sock
5 set s [socket unix.dgram.server unix.sock]
7 puts "Listening on dgram socket [$s sockname]"
9 set count 0
11 # For each request...
12 $s readable {
13         # Get the request (max 80 chars) - need the source address
14         set buf [$s recvfrom 80 addr]
16         puts -nonewline "read '$buf' from client $addr"
18         try {
19                 set result "$buf = [expr $buf]"
20         } on error {msg} {
21                 set result "Error: $buf => $msg"
22         }
24         puts ", sending '$result' to client $addr"
26         # Send the result back to where it came from
27         $s sendto $result $addr
30 # Handle signals so the socket is removed on exit
31 signal handle SIGINT SIGTERM
33 catch -signal {
34         vwait done