[prev in list] [next in list] [prev in thread] [next in thread]
List: jabber-jdev
Subject: [JDEV] request for help (jabber protocol - xml streams)
From: zak <zsy () photoalley ! com>
Date: 2001-12-28 1:05:31
[Download RAW message or body]
hi all,
i'm just starting out and was just trying to write a really simple test to
connect to a jabber server. however, for some reason my parser hangs when
trying to read the first <stream:stream response from the server. here is
the code for reference. i know it's really bad code, but like i said, i was
trying to do something fast and simple as an example. not sure if i'm making
some protocol errors or if i'm hanging because something is blocking? any
ideas?
thanks, zak.
public class JabTest
{
public static void main(String[] args)
{
String init = "<?xml version='1.0' encoding='UTF-8' ?> " +
"<stream:stream to='jabber.org' xmlns='jabber:client' " +
"xmlns:stream='http://etherx.jabber.org/streams'>";
String terminate = "</stream:stream>";
Socket s = null;
PrintWriter out = null;
BufferedReader in = null;
try
{
InetAddress addr = InetAddress.getByName("jabber.org");
s = new Socket(addr, 5222);
try
{
out = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(s.getOutputStream(), "UTF8")), true);
}
catch (UnsupportedEncodingException uee)
{
throw new RuntimeException("encoding error - " + uee.getMessage());
}
out.println(init);
out.flush();
try
{
in = new BufferedReader(
new InputStreamReader(s.getInputStream(), "UTF8"));
}
catch (UnsupportedEncodingException uue)
{
System.out.println("encoding error - " + uue.getMessage());
}
InputSource is = new InputSource(in);
XMLReader xr = XMLReaderFactory.createXMLReader(
"org.apache.xerces.parsers.SAXParser");
xr.setContentHandler(new MyHandler());
xr.parse(is); // this call hangs
out.println(terminate);
}
catch (UnknownHostException uhe)
{
System.out.println("unknown host - " + uhe.getMessage());
}
catch (IOException ioe)
{
System.out.println("IO Error - " + ioe.getMessage());
}
catch (SAXException se)
{
System.out.println("SAX exception - " + se.getMessage());
}
finally
{
try
{
in.close();
out.close();
s.close();
}
catch (IOException ioe)
{
System.out.println("IO exception - " + ioe.getMessage());
}
}
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic