All pastes #474066 Raw Edit

Someone

public text v1 · immutable
·published 2007-05-06 16:21 UTC
rendered paste body
set port 7801

proc localsockfree {sock} {
  if {[catch {socket -server {} $sock} rc]} {
    return 0
  } else {
    # server could be started, so the port is not in use locally
    catch {close $rc}
    return 1
  }
}


proc accept {chan addr port} {
  fconfigure $chan -blocking 0 -buffering line
  fileevent $chan readable [list getlines $chan $addr $port]
  puts $chan "\n"
}

proc getlines {chan addr port} {
  global mysql
  set string [gets $chan]
  puts $chan "$string recieved"
  close $chan
}


# start socket server and wait... :>
if {[localsockfree $port]} {
  socket -server accept $port
} { return "port $port already used.." }

vwait forever