Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing an xmpp client in java - stuck in the first step
    primarykey
    data
    text
    <p>I am trying to write an xmpp client to send/recieve messages from gtalk.</p> <p>Before I actually started with the implementation I thought of developing a prototype to see if I am able to to get a message through to gtalk.</p> <p>I wrote the following code and am now stuck in the part where I am supposed to request google before starting an encrypted connection.</p> <pre><code>import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.Socket; import java.net.UnknownHostException; public class XmppConnect { static String initiate_conn="&lt;?xml version=\"1.0\"?&gt;\n\r&lt;stream:stream to=\"google.com\"\n\rversion=\"1.0\"\n\rxmlns=\"jabber:client\"\n\rxmlns:stream=\"http://etherx.jabber.org/streams\"&gt;\n"; static String start_tls="&lt;starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/&gt;"; public static void main(String [] args) { try { Socket connection = new Socket("talk.google.com", 5222); DataInputStream input = new DataInputStream(connection.getInputStream()); BufferedReader d = new BufferedReader(new InputStreamReader(input)); OutputStream to_server = null; String responseLine; to_server = connection.getOutputStream(); to_server.write(initiate_conn.getBytes()); responseLine = d.readLine(); System.out.println("Server: " + responseLine); to_server.write(start_tls.getBytes()); responseLine = d.readLine(); System.out.println("Server: " + responseLine); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } </code></pre> <p>I am able to send the following to google</p> <pre><code>&lt;starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/&gt; </code></pre> <p>and in reply I expect the following</p> <pre><code>&lt;proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/&gt; </code></pre> <p>But I don't get anything back from the server.</p> <p>The screenshot from wireshark is as attached.</p> <p>Request your help and please don't tell me to use already existing xmpp libraries cause I just don't want to.</p> <p>Regards, Manu!</p> <p><img src="https://i.stack.imgur.com/KMreo.png" alt="Screenshot of WireShark"></p> <p><strong><em>Update</em></strong></p> <p>Have found the solution. The working code is as under:</p> <p>The code which works for now is as under.</p> <p>Now I will work on the TLS implementation and get back here incase of any doubts :) :)</p> <pre><code>import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.Socket; import java.net.UnknownHostException; public class XmppConnect { static String initiate_conn="&lt;stream:stream to=\"gmail.com\" version=\"1.0\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\"&gt;"; static String start_tls="&lt;starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/&gt;"; public static void main(String [] args) { try { Socket connection = new Socket("talk.google.com", 5222); DataInputStream input = new DataInputStream(connection.getInputStream()); BufferedReader d = new BufferedReader(new InputStreamReader(input,"UTF-8")); BufferedWriter to_server = new BufferedWriter( new OutputStreamWriter(connection.getOutputStream(),"UTF-8") ); String responseLine=""; to_server.write(initiate_conn); to_server.flush(); int in; while(!(responseLine.contains("&lt;/stream:features&gt;"))) { responseLine += (char)d.read(); } System.out.println("Server: " + responseLine); to_server.write(start_tls); to_server.flush(); responseLine=""; while(!(responseLine.contains("&lt;proceed xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/&gt;"))) responseLine += (char)d.read(); System.out.println("Server: " + responseLine); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload