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 7827571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:56:35+00:00 2026-06-02T09:56:35+00:00

Have setup an ssl connection app, have already setup connection between client and server

  • 0

Have setup an ssl connection app, have already setup connection between client and server using single thread. Since my app deals with remote desktop access, i am trying to implement threading.

Don’t know why the application just stops after creating socket, it neither fails nor performs SSLhandshake. Same code when executed under single thread works smoothly, but under multi-thread its not. Have tried logcat, it couldnt help me out. Out of 10-15 tries, application works fine 1 time, but goes to not responsive mode.

Any idea where i am hitting wrong ?Here is the code. Any answer please do share.

Main activity:

    Thread t = new Thread() {
        public void run() {
            try{
                Log.d(TAG, "Opening RFB socket");
                rfb = new rfbProtocol(ip, port, RFB_ClientActivity.getContext());
                txt_notify.append("Connection done");
                Log.d(TAG, "RFB socket openned");
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        progress.setMessage("Connection established..\nPlease wait");
                    }
                });
                processProtocol(progress);
            }catch(Exception e){
                if(maintainConnection){
                    if(progress.isShowing())
                        progress.dismiss();
                    txt_notify.append( "Connection failure:\n" + e.getMessage() );
                    Log.d(TAG,"RFB socket failure");
                    e.printStackTrace();
                }
            }
        }
    };
    t.start();

rfbProtocol:

rfbProtocol(String h, int p, Context c) throws Exception {
    // TODO Auto-generated constructor stub
    host = h;
    port = p;
    cont = c;
    try {
        // Setup the SSL context to use the truststore and keystore
        Log.d(TAG, "Initializing SSL connection");
        SSLContext ssl_context = createSSLContext(cont);              
        SSLSocketFactory socketFactory = (SSLSocketFactory) ssl_context.getSocketFactory();
        Log.d(TAG,"Creating RFB socket");
        socket = (SSLSocket) socketFactory.createSocket(host, port);
        Log.d(TAG,"RFB Socket created");
        dataOut = socket.getOutputStream();
        dataIn = new DataInputStream(new BufferedInputStream(socket.getInputStream(), 16384));
        close = false;
        Log.d(TAG,"SSL connection done");
    } catch (Exception e) {
        // TODO Auto-generated catch block
        throw(e);
    }
}

private SSLContext createSSLContext(final Context cont) throws Exception{
    SSLContext ssl_cont = null;
    try {
        // Setup truststore
        Log.d(TAG, "TrustStore - Initializing");   
        KeyStore trustStore = KeyStore.getInstance("BKS");
        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        InputStream trustStoreStream = cont.getResources().openRawResource(R.raw.clienttruststore);
        trustStore.load(trustStoreStream, "client".toCharArray());
        trustManagerFactory.init(trustStore);
        Log.d(TAG, "TrustStore - Initialized");

        // Setup keystore
        Log.d(TAG, "KeyStore - Initializing");
        KeyStore keyStore = KeyStore.getInstance("BKS");
        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        InputStream keyStoreStream = cont.getResources().openRawResource(R.raw.client);
        keyStore.load(keyStoreStream, "client".toCharArray());
        keyManagerFactory.init(keyStore, "client".toCharArray());
        Log.d(TAG, "KeyStore - Initialized");

        ssl_cont = SSLContext.getInstance("TLS");
        ssl_cont.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); 
    } catch (Exception e) {
        // TODO Auto-generated catch block
        throw(e);
    }
    return ssl_cont;
}

Application just hangs after “RFB Socket created”, followed by activity logged by intent in the logcat. Thanks in advance.

  • 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-06-02T09:56:37+00:00Added an answer on June 2, 2026 at 9:56 am

    Since ssl server socket is used and i have my own java host, need to initiate handshake protocol manually. This worked for me !

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

Sidebar

Related Questions

I have successfully setup my MySQL server to support SSL connections I'm just wondering
I have a C++ client app that uses Boost ASIO to make SSL connections
I have implemented a secure SSL connection on the SQL Server 2005 server. I
I have setup a Django project on my laptop and build my first app.
I have setup web dav on windows server 2008. It seems to work fine
I have an asp.net app, I am using vs 2010, and I connect to
I have been using an Ubuntu 8.04 server with fail2ban for a while now
Sorry, this is along one to document.. OLD SETUP I have a J2ME client
I have log4net setup and configured to insert into a sql server 2005 table.
I have a IIS set up to only accept client connections with a SSL

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.