All pastes #473245 Raw Edit

Someone

public text v1 · immutable
·published 2007-05-06 03:40 UTC
rendered paste body
# Initialise the state
after 5000 set state timeout
set server [socket -server Server 10444]

proc Server {chan addr port} {
   global state connectionInfo
   set state accepted
   set connectionInfo $chan
   fileevent $chan readable [list foo $chan]
   fileevent $chan writeable [list foo $chan]
}

proc foo {chan} {
puts $foo "foo [channels]"
puts $chan "chan [channels]"
	set type [gets $chan]
	if{$type="chans"} {
		puts $chan "[channels]"
	} else {
		puts $chan "Invalid Type"
	}
}

# Wait for something to happen
vwait state

# Clean up events that could have happened
#close $server
after cancel set state timeout

# Do something based on how the vwait finished...
switch $state {
   timeout {
      putlog "no connection on port 12345"
   }
   accepted {
      putlog "connection: $connectionInfo"
      puts [lindex $connectionInfo 0] "Hello there!"
   }
}