The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

powerfu (6) [Avatar] Offline
#1
Hi Iain,

After I tried to crack your code for a full day and showed no progress, I decided to get help from you or others.

Basically I tried to create a client using Java. Before I do that, I tried to write simple code to talk to the server. I have tried the following code:

String seq1 = "<stream:stream>";
String seq2 = "</stream:stream>";
HttpURLConnection conn=null;
try {
URL url = new URL("http","128.132.177.146", 5222, "/");
conn=(HttpURLconnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
} catch (IOException e) {}

try {
OutputStream os = conn.getOutputStream();
os.write(seq1.getBytes());
os.write(seq2.getBytes());
} catch (IOException e) {}

I have also tried to create socket or even use XMPPConnection in Smack. However, there is an org.xml.sax.SAXParseException being thrown for all of them. The exception said "The root element is required in a well-formed document."

I have no problem of using putty to connect to the server. I wonder how I can write Java code to connect. Any hint will be greatly appreciated.

Thanks,

Yat
iain (56) [Avatar] Offline
#2
Re: Connection between client and server using Java
Hi,

The XMPP/Jabber protocol is separate from HTTP. You can't use an HTTP connection. Instead, open a plain socket and send and receive data. The HTTP connection will send HTTP headers which are not understood by XMPP/Jabber servers.

-iain