Posted to tcl by aku at Fri May 17 16:27:17 GMT 2013view raw

  1. socket -server answer $port
  2.  
  3. proc answer {socketChannel hostremote portremote} {
  4.  
  5. # Block access from the outside. Accept only local system and
  6. # local LAN.
  7. if {![string match 192.168.193.* $hostremote] &&
  8. ![string match 127.0.0.* $hostremote]} {
  9. puts "rejected $hostremote/$portremote"
  10. close $socketChannel
  11. return
  12. }
  13.  
  14. puts "accepted $hostremote/$portremote"
  15.  
  16. #puts $hostremote
  17. #puts [fconfigure $socketChannel]
  18.  
  19. fileevent $socketChannel readable [list readIt $socketChannel]
  20. }
  21.