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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:59:02+00:00 2026-05-30T08:59:02+00:00

I have a relatively simple program where I try establish Client Server connection and

  • 0

I have a relatively simple program where I try establish Client Server connection and at the same time I use threads in the client side to allow for multiple connections.

I run the server and then the server invokes the client constructor and passes the port connection to the client and the thread is started on the client side.

The problem I have is that when I run the server side it doesn’t want to go beyond the constructor call. It seems to get stuck at the constructor.

Sorry all this sounds a bit confusing

Any thoughts perhaps

this is the server side

ServerMultipleThreads()
{


    System.out.println("Starting the server first...");
    try
    {
        ServerSoc = new ServerSocket(7777);
        listening = true;

    }
    catch(Exception e)
    {
        System.out.println(e.toString());
        System.exit(1);

    }

    System.out.println("The server has started running");

    while(listening)
    {
        try
        {
            //creating the client socket and starting the new client session
            new ClientSession(ServerSoc.accept());
            System.out.println("The clientSession was called");
            in = new DataInputStream(clientSocket.getInputStream());
            BufferedReader is = new BufferedReader(new InputStreamReader(in));
            os = new PrintStream(clientSocket.getOutputStream());

            while(true)
            {
                line = is.readLine();
                PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("myFile,txt")), true);
                out.println(line);
            }


        }
        catch(IOException ioe)
        {
                System.out.println(ioe.toString());
        }
    }

}

and this is on client side

ClientSession(Socket s)
{
    clientSocket = s;

    try
    {


        out = new PrintWriter(clientSocket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        out.println("Welcome");

    }
    catch(IOException exe)
    {
        System.out.println(exe.toString());

    }
    //starting the thread
    while(runner == null)
    {
        runner = new Thread(this);
        runner.start();
    }
}

public void run()
{
    while(runner == Thread.currentThread())
    {
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
        String stdIn;

        try
        {
            while((stdIn = buf.readLine()) != null)
            {
                out.println(stdIn);
            }
        }
        catch(IOException exe)
        {
            exe.toString();

        }
        try
        {
            Thread.sleep(10);
        }
        catch(InterruptedException e){}

    }

Kind regards
Arian

  • 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-30T08:59:04+00:00Added an answer on May 30, 2026 at 8:59 am

    That is because ServerSocket.accept() blocks until it receives a client request.
    You need to have a client calling the server, something like this:

    Socket socket = new Socket(host, port);
    InputStream in = socket.getInputStream();
    // write some data...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a (relatively) simple tcp client/server chat program for my
I have a relatively simple select statement in a VB6 program that I have
I have a relatively simple program that currently uses 1 thread (main). The application
I have a simple HTML server program that listens on port 8000 for a
I have a relatively simple site that I'm working up for an intranet environment.
We have are relatively simple Reporting Services report that our users commonly export to
I have a relatively simple form which asks a variety of questions. One of
I have a relatively simple application which I need to make native Mac OSX
I have a relatively simple query joining two tables. The Where criteria can be
I have a relatively simple question that I cannot seem to find the answer

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.