build: Update autosetup to v0.6.6-8-g062d650
[jimtcl.git] / examples / ssl.server
blob7ccb101cd4b739552bb920b58bb121ba7fccb015
1 # Example of a ssl encrypted, tcp server which sends a response
3 # Listen on port 20000. No host specified means 0.0.0.0
4 set s [socket stream.server 20000]
6 $s readable {
7         # Clean up children
8         os.wait -nohang 0
9         set sock [[$s accept addr] ssl -server certificate.pem key.pem]
10         puts "Client address: $addr"
12         # Make this server forking so we can accept multiple
13         # simultaneous connections
14         if {[os.fork] == 0} {
15                 $s close
17                 $sock buffering line
19                 # Get the request (max 80 chars) - need the source address
20                 while {[$sock gets buf] >= 0} {
21                         if {$buf eq ""} {
22                                 break
23                         }
24                         set buf [string trim $buf]
25                         puts -nonewline "read '$buf'"
27                         try {
28                                 set result "$buf = [expr $buf]"
29                         } on error {msg} {
30                                 set result "Error: $buf => $msg"
31                         }
33                         puts ", sending '$result'"
35                         # Send the result back to where it came from
36                         $sock puts $result
37                 }
38         }
40         $sock close
43 vwait done