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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:56:37+00:00 2026-05-25T02:56:37+00:00

I’m trying to create a secure TCP/IP connection between my android client and java

  • 0

I’m trying to create a secure TCP/IP connection between my android client and java server. Cryptography by far is not my strong point. I know I have to use the Bouncy Castle keystores, but I’m stuck.

I need to create a self signed cert that I can use with the server and the client. This is where I’m stuck.

         InputStream clientTruststoreIs = getResources().openRawResource(R.raw.bks);
         KeyStore trustStore = null;
         trustStore = KeyStore.getInstance("BKS");
         trustStore.load(clientTruststoreIs, "123456".toCharArray());
        InetAddress serverAddr = InetAddress.getByName(serverIpAddress);
        SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();

        sslSocket = (SSLSocket) sslsocketfactory.createSocket(serverAddr, 2222);
        inputStream =  sslSocket.getInputStream();  
        Log.d("TEST", "\n1 input");

It connects fine, it shows the connection on the server side, however the line inputStream = sslSocket.getInputStream() is completely locking/not returning. I’m not sure if I did any of the bouncy castle set up properly, or if the server is properly set up. Please help, I’m at my wits’ end….

Edit:
I modified the server so that it sends data upon connection and still nothing, and I changed the order of where I get my input and output streams, and then it locked where I was getting the output stream:

        sslSocket = (SSLSocket) sslsocketfactory.createSocket(serverAddr, 9999);
        outputStream = sslSocket.getOutputStream();
        Log.d("test", "--**--- created socket 2.0 outputsreams"); // does not reach here
        outputStreamWriter = new OutputStreamWriter(outputStream);
        bufferedWriter = new  BufferedWriter(outputStreamWriter);         
        inputStream =  sslSocket.getInputStream();  
        inputStreamReader = new InputStreamReader(inputStream);
        bufferedReader = new BufferedReader(inputStreamReader);
        ...
        String line = bufferedReader.readLine(); // where I'd expect it to lock...

So still no luck, no timeout, no exception, it just waits there…

  • 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-25T02:56:38+00:00Added an answer on May 25, 2026 at 2:56 am

    I think your problem is similar to this. The same workflow holds for SSL socket connections:

    However, the basics are much the same as they are in this program:

    Open a socket.

    Open an input stream and output stream to the socket.

    Read from and write to the stream according to the server’s protocol, call flush() on the stream when you are done with a message.

    Close the streams.

    Close the socket.

    So you should

    1. Send a request to your server first by writing to the server’s OutputStream from the client side, flush when you’re done.
    2. The server will then receive the message through its InputStream and can in return write to its OutputStream, again flushing when done.
    3. Read the response from the client side using the InputStream, start from 1. until you are done.

    Finally, you should close all streams.

    Flushing and sending a request first before trying to read a response on the client side should stop the "hanging behaviour".


    Edit: Are you sure that you use SSLServerSocketFactory on the server? It looks like you are trying to use SSLSocketFactory both for client and server. That’s not going to work. I googled this tutorial, that’s basically similar to what your code should look like.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have thousands of HTML files to process using Groovy/Java and I need to

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.