Forum OpenACS Q&A: Response to Jabber Client for AOLserver

Collapse
Posted by Tom Jackson on

Most of the code is inside a c module. Here is what runs the client right now:

nsv_set jabber_conn user [ns_jabber new "user@server/res" "pass" ]

# start this jabber_conn and auth the conn
set j [nsv_get jabber_conn user]
ns_jabber start $j

# wait a while for a response, this could hang the server
ns_jabber poll $j 50000  ;# microseconds
ns_jabber auth $j


proc do_poll { j } {

  while { 1==1} {
   if {![ns_jabber stateget $j]} {
    ns_log Notice "Jabber Conn $j is Off"
    break
   }
   ns_jabber poll $j -1
  }

}

# Schedule the polling proc and see what happens
ns_schedule_proc -once -thread 5 do_poll $j

However, all the new, start and auth procedures should be moved into the scheduled procedure and inside the while loop. The value of the state can be used to decide if a new connection is needed. If the connection goes down, it can restart immediately. If the whole thread dies, then it will be rescheduled.

Also right now I haven't protected the send socket. So problems could occur.