I have started coding with Jabber but am having problems early on with what i suspect in bad formatting in the Xml.<br>
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.<br>
I put together this quick example below to illustrate the problem.<br>
Any help would be greatly appreciated<br>
<br>
Paul<br>
<br>
import java.util.*;<br>
import java.net.*;<br>
import java.io.*;<br>
<br>
public class JabberTest implements Runnable<br>
{<br>
private Socket socket;<br>
private BufferedReader dataIn;<br>
private PrintWriter dataOut;<br>
private String line;<br>
<br>
public JabberTest()<br>
{<br>
new Thread(this).start();<br>
}<br>
<br>
public void run()<br>
{<br>
String hostname = "<a href="http://netmindz.net">netmindz.net</a>";<br>
String line;<br>
<br>
System.out.println("Connecting..");<br>
try<br>
{<br>
socket = new Socket(hostname,5222);<br>
dataIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));<br>
dataOut = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true);<br>
<br>
String s1 = "<?xml version='1.0'?>";<br>
s1 += "<stream:stream ";<br>
s1 += "xmlns:stream='<a href="http://etherx.jabber.org/streams">http://etherx.jabber.org/streams</a>' ";<br>
s1 += "xmlns='jabber:client' ";<br>
s1 += "to='<a href="http://netmindz.net">netmindz.net</a>'/>";<br>
<br>
send(s1);<br>
while((line = dataIn.readLine()) != null)<br>
{<br>
System.out.println(line);<br>
}<br>
<br>
String s2 = " <iq type='set' id='reg2'> ";<br>
s2 += " <query xmlns='jabber:iq:register'> ";<br>
s2 += " <username>test user</username> ";<br>
s2 += " <password>test user</password> ";<br>
s2 += " </query> ";<br>
s2 += " </iq> ";<br>
<br>
send(s2);<br>
<br>
while((line = dataIn.readLine()) != null)<br>
{<br>
System.out.println(line);<br>
}<br>
<br>
socket.close();<br>
}<br>
catch(Exception e)<br>
{<br>
e.printStackTrace();<br>
}<br>
}<br>
<br>
public void send(String message) throws java.io.IOException<br>
{<br>
dataOut.println(message);<br>
dataOut.flush();<br>
}<br>
<br>
public static void main(String[] params)<br>
{<br>
new JabberTest();<br>
}<br>
<br>
}<br>