From: Cameron L. <Ca...@ph...> - 2008-12-19 18:46:03
|
On Fri, Dec 19, 2008 at 12:27:58PM -0500, polishookm wrote: . . . > The code below, from the thread with David, is the only code I'm running > at this point. > > With gets, I get this result in a terminal (I'm entering the ^C after a > short while, of course) > > & tclsh port.tcl > ^C > > > Using read instead of gets, this returns in the terminal immediately. > > & tclsh port.tcl > read: '<?xml version='1.0'?><stream:stream xmlns='jabber:client' > xmlns:stream='http://etherx.jabber.org/streams' id='2298415925' > from='jabber.org' xml:lang='en'>' > & > > > > ########################################### > set the_server "jabber.org" > set the_port 5222 > > set s [socket $the_server $the_port] > fconfigure $s -buffering line -blocking 0 > fileevent $s readable [list sock_read $s] > > proc sock_read {port} { > if {![eof $port]} { > set line [string trim [gets $port]] > if {[string length $line]} { > puts "read: '$line'" > set ::done 1 > } > } > } > > puts $s "<stream:stream \ > to='$the_server' \ > xmlns='jabber:client' \ > xmlns:stream='http://etherx.jabber.org/streams'>" > > vwait ::done > close $s > exit > ########################################### > > > > > > > > > Cameron Laird wrote: > > On Fri, Dec 19, 2008 at 09:20:03AM -0500, polishookm wrote: > > . > > . > > . > > This alarms me. . . . Let me see if I understand this correctly: you followed David's advice, you've briefly reported your own experi- ence, and you've provided a complete code sample that allows others to reproduce it--right? You deserve an answer. Here it is: there's a slight confusion afoot (well, two or three, but all most of them can be neglected for now). The [gets $port] and coding in terms of $line all assume what the Tcl community commonly understands as a "line", that is, a string which terminates in \n. That's not what Jabber does. Jabber speaks XML (XMPP, in fact, I believe). Its responses end with '>' rather than \n. For me, that solves the mystery. I think you deserve more, though. Your little application, adapted (?) from David's recommendation, is flawed. If the purpose is only to receive a single transmission from Jabber, there are simpler and briefer ways to express it. If you're trying to build up to something that can carry on an extended conversation with Jabber, you've got cor- rections to make. Also, if your networking stack changes, or Jabber is updated to provide somewhat different responses, the code above will fail. Your move, next: do you want to pursue this? |