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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:21:50+00:00 2026-05-31T00:21:50+00:00

I am creating a SSL Server and Client in Java. The point of the

  • 0

I am creating a SSL Server and Client in Java. The point of the program is to mimic a movie theater program. I can establish the connection but when I attempt to “reserve” a seat the program crashes. I get the following error:

Server aborted: javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

This is my Server Code

// SSL Server
import java.net.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocketFactory;

public class SSL_Server {


public static void main(String[] args) {
    int port = 2018;

    System.setProperty("javax.net.ssl.keyStore","mySrvKeystore");
    System.setProperty("javax.net.ssl.keyStorePassword","123456");
    ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();
    ServerSocket ssocket = null;
    System.out.println("SSL_Server started");

    final ExecutorService threadPool = Executors.newCachedThreadPool();

    try {
        ssocket = ssocketFactory.createServerSocket(port);
        InetAddress myIP =InetAddress.getLocalHost();
        System.out.println(myIP.getHostAddress());

        while(true){
            Socket aClient = ssocket.accept();
            //create a new thread for every client
            threadPool.submit(new SSL_ClientHandler(aClient));
        } 

    } 
    catch(Exception e) {
        System.err.println("Server aborted:" + e);
    } finally {
        try{
            ssocket.close();
        } catch (Exception e){
            System.err.println("could not close connection properly" + e);
        }
    }
    System.out.println("connection was closed successfully");
}
}

The following is my client code

//SSL Client
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.StringTokenizer;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocketFactory;

public class TCP_Client {


public static void main(String[] args) throws IOException{
//  SSL_Client newClient = new SSL_Client();
//  Lock lock = new ReentrantLock();
    boolean validInput = false;

    BufferedReader din;
    PrintStream pout;

    int port = 2018;
    BufferedReader stdinp = new BufferedReader(new InputStreamReader(System.in));
    String line = "done";
    StringTokenizer st;
    String hostname; 
    String task = "done";


    if(args.length>0)
        hostname = args[0];
    else
        hostname = "localhost";

    SocketFactory socketFactory = SSLSocketFactory.getDefault();
    //Socket socket = socketFactory.createSocket(hostname, port);

    while(true)
    {
        try{
            //read input
            while(!validInput)
            {
                System.out.println("Please enter a valid command or 'done' to finish.");
                line = stdinp.readLine();
                st = new StringTokenizer(line);
                task = st.nextToken();
                if(task.equals("reserve") || task.equals("search") || task.equals("delete") || task.equals("getinfo") || task.equals("done"))
                {
                    validInput =true;
                    break;
                }
                System.out.println("Invalid command.  Please enter another command or 'done' to escape.");
            }
            if(task.equals("done"))
            {
                break;
            }
            validInput = false;//reset for next line read in

            //create a new socket every time
            //Socket socket = new Socket(hostname, port);

            Socket socket = socketFactory.createSocket(hostname, port);
            din = new BufferedReader (new InputStreamReader    (socket.getInputStream()));
            pout = new PrintStream (socket.getOutputStream());

            pout.println(line);
            pout.flush();

            //print out response from server
            System.out.println(din.readLine());

        } catch (Exception e){
            System.err.println("Server aborted: " + e);
        }
    }   
}
}
  • 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-31T00:21:52+00:00Added an answer on May 31, 2026 at 12:21 am

    “Unable to find valid certification path to requested target” means that your truststore doesn’t trust the server certificate. Import it into your truststore, or have it signed by a recognized CA.

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

Sidebar

Related Questions

We are creating an extranet application that will use client/server SSL certificates to enhance
I'm trying to create a TCP connection and send/read data that uses SSL, but
How can I gracefully shutdown a Java SSL session without closing the underlying socket?
When creating a SSL server, I got this exception: Default SSL context init failed:
Creating a server-side socket will fail if I'm trying to use the same port
I'm creating a web service (and test client) that uses mutual authentication. I've used
I created an SSL server cert at CAcert . When I try to fetch
Transfering databases between servers or creating a copy of db within the server's instance
I am attempting to try to install my SSL certificate on a server and
I am using self signed certificate for HTTPS connection to and from Axis2 server.

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.