From 847653905d7058b3d5f67642f07d602f644c4b2c Mon Sep 17 00:00:00 2001 From: fritzy Date: Sat, 29 Mar 2008 18:45:29 +0000 Subject: [PATCH] * initial checkin git-svn-id: svn://netflint.net/xmpphp@1 ef36c318-a008-4979-b6e8-6b496270793b --- cjp.php | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 cjp.php diff --git a/cjp.php b/cjp.php new file mode 100644 index 0000000..2ddbaf7 --- /dev/null +++ b/cjp.php @@ -0,0 +1,60 @@ +'; + var $disconnect = false; + + function XMLStream($host, $port) { + $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + $this->host = $host; + $this->port = $port; + #set up the parser + $this->parser = xml_parser_create(); + xml_set_object($this->parser, $this); + xml_set_element_handler($this->parser, 'startXML', 'endXML'); + xml_set_character_data_handler($this->parser, 'charXML'); + } + + function connect() { + if(socket_connect($this->socket, $this->host, $this->port)) { + socket_write($this->socket, $this->stream_start); + } + } + + function process() { + while(!$this->disconnect) { + xml_parse($this->parser, socket_read($this->socket, 1024), False); + # parse whatever we get out of the socket + } + } + + function startXML($parser, $name, $attr) { + print "Start:"; + print $name; + print "\n"; + print $attr; + print "\n"; + print "----"; + } + + function endXML($parser, $name) { + print "End: " . $name; + print "\n"; + } + function charXML($parser, $data) { + print "Data: " . $data; + print "\n"; + } +} + +$conn = new XMLStream('netflint.net', 5222); +$conn->stream_start = '\n'; +$conn->connect(); +$conn->process(); +