Version 1 of Peer to peer

Updated 2005-07-25 01:28:48

Zarutian 2005-07-27-01:15 Here is a super simple peer-to-peer system:

  set listening_port 8050
  rename send old_send
  proc log {message {level 5}} {
    # levels
    #   1 mind numbing detail
    #   2 less numbing
    #   3 noteworthy
    #   4 milestone
    #   5 landmark
    puts "[clock seconds]:[set level]: $message"
  }
  proc send {chan data} {
    log [info level 0] 1
    catch {
      puts $chan $data
      flush $chan
    }
  }
  proc accept {chan ipnr portnr} {
    log [info level 0] 2
    fconfigure $chan -encoding utf-8
    send $chan "hello $ipnr $portnr"
    send $chan "comment This is a super simple peer to peer node"
    send $chan "ready"
    fileevent $chan readable [list handle_connection $chan $ipnr $portnr ]
  }

...work in progress