Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7184721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:15:33+00:00 2026-05-28T18:15:33+00:00

I am trying to write an xmpp client to send/recieve messages from gtalk. Before

  • 0

I am trying to write an xmpp client to send/recieve messages from gtalk.

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.

I wrote the following code and am now stuck in the part where I am supposed to request google before starting an encrypted connection.

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="<?xml version=\"1.0\"?>\n\r<stream:stream to=\"google.com\"\n\rversion=\"1.0\"\n\rxmlns=\"jabber:client\"\n\rxmlns:stream=\"http://etherx.jabber.org/streams\">\n";
static String start_tls="<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>";
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();
        }
    }

}

I am able to send the following to google

<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>

and in reply I expect the following

<proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>

But I don’t get anything back from the server.

The screenshot from wireshark is as attached.

Request your help and please don’t tell me to use already existing xmpp libraries cause I just don’t want to.

Regards,
Manu!

Screenshot of WireShark

Update

Have found the solution. The working code is as under:

The code which works for now is as under.

Now I will work on the TLS implementation and get back here incase of any doubts 🙂 🙂

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="<stream:stream to=\"gmail.com\" version=\"1.0\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\">";
static String start_tls="<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>";
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("</stream:features>")))
            {
                responseLine += (char)d.read();   
            }
            System.out.println("Server: " + responseLine);
            to_server.write(start_tls);
            to_server.flush();
            responseLine="";
            while(!(responseLine.contains("<proceed xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>")))
                responseLine += (char)d.read();   
            System.out.println("Server: " + responseLine);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:15:33+00:00Added an answer on May 28, 2026 at 6:15 pm

    Check the SMACK which provides a nice XMPP stack for Java.
    It’s well documented and easy to use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to code a small XMPP gtalk client in java. I know
Trying to write a javascript bookmarklet to jump from a front end link into
I'm trying write a simple perl script that reads some fields from a password
Im' trying to write a class BrokenObjectException class derivated from Exception. But in Eclipse
Trying to write a python application that downloads images from an RSS feed, and
I'm trying to authenticate with an XMPP server using SASL. /** * Send Authentication,
I'm trying write a java program to send live microphone data over UDP, then
I'm trying to write a simple XMPP application on Android using asmack, but I've
I am trying write a script where when a user clicks on a link,
I m trying write code that after reset set up rrpmax as 3000. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.