[jdev] Server closing connection early
Jabber X
jabberlists at googlemail.com
Sun Nov 20 14:01:40 CST 2005
I have started coding with Jabber but am having problems early on with what
i suspect in bad formatting in the Xml.
I send the initial xml to make the stream connection and then try to
register an account but the server closes the connection. When trying this
on a telnet client it does give me a stream error which says disconnected.
Occasionally upon trying other xml such as a login stream it might say
invalid xml.
I put together this quick example below to illustrate the problem.
Any help would be greatly appreciated
Paul
import java.util.*;
import java.net.*;
import java.io.*;
public class JabberTest implements Runnable
{
private Socket socket;
private BufferedReader dataIn;
private PrintWriter dataOut;
private String line;
public JabberTest()
{
new Thread(this).start();
}
public void run()
{
String hostname = "netmindz.net <http://netmindz.net>";
String line;
System.out.println("Connecting..");
try
{
socket = new Socket(hostname,5222);
dataIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
dataOut = new PrintWriter(new OutputStreamWriter(socket.getOutputStream
()),true);
String s1 = "<?xml version='1.0'?>";
s1 += "<stream:stream ";
s1 += "xmlns:stream='http://etherx.jabber.org/streams' ";
s1 += "xmlns='jabber:client' ";
s1 += "to='netmindz.net <http://netmindz.net>'/>";
send(s1);
while((line = dataIn.readLine()) != null)
{
System.out.println(line);
}
String s2 = " <iq type='set' id='reg2'> ";
s2 += " <query xmlns='jabber:iq:register'> ";
s2 += " <username>test user</username> ";
s2 += " <password>test user</password> ";
s2 += " </query> ";
s2 += " </iq> ";
send(s2);
while((line = dataIn.readLine()) != null)
{
System.out.println(line);
}
socket.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void send(String message) throws java.io.IOException
{
dataOut.println(message);
dataOut.flush();
}
public static void main(String[] params)
{
new JabberTest();
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.jabber.org/jdev/attachments/20051120/0d407c0d/attachment-0002.htm>
More information about the JDev
mailing list