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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:21:55+00:00 2026-05-23T13:21:55+00:00

I am new to socket programming and trying to write a simple cmd line

  • 0

I am new to socket programming and trying to write a simple cmd line chat application.
Now i use the code below to accept a connection and then create a new thread for the same,but no new thread is created ,and no more then one clients are supported(which is usual when threads are not used),

public class chatserver extends Thread{
    public static Socket client;
    public static void main(String a[]) throws Exception{
        ServerSocket srv = new ServerSocket(4444);
        if((client = srv.accept())!=null){
            new newthread(client);
        }
    }
}
class newthread extends Thread{
    private Socket client;
    public newthread(Socket client){
        super("chatchild");
        this.client = client;
        start();
}

why the threads are not created?I reffered examples at “oracle.com” one of which contains the code for the same but I am not able to figure out the exact sequence what will happen and when???The snippet from exaple code that accepts a connection and creates the thread::

while (listening)
        new KKMultiServerThread(serverSocket.accept()).start();

now here listening is bool var sat to true but it is never set to false anywhere in the code.???How does this work?

  • 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-23T13:21:56+00:00Added an answer on May 23, 2026 at 1:21 pm

    You have to continually call accept() to create the other threads:

    public static void main(String a[]) throws Exception{
        ServerSocket srv = new ServerSocket(4444);
    
        while (listening) {
            new newthread(srv.accept());
        }
    }
    

    The listening variable should be set to false if and when you want to stop the server.

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

Sidebar

Related Questions

I am quite new to socket programming. I was trying to make p2p communication
I'm new to C89, and trying to do some socket programming: void get(char *url)
I'm completely new to socket programming with C#, I'm trying to get two running
New to Linux programming in general. I am trying to communicate with a kernel
In new C++ code, I tend to use the C++ iostream library instead of
I'm trying to do some Socket programming in Java, and I'm using the BufferedStreamReader.read(char[])
For last 48 hours, I have been trying to understand Multithreading and Socket Programming
I am new to socket programming and I am looking for more info about
I'm newbie. Pointer make my crazy T_T. Now, I'm do the socket programming project.
New to both Ruby and Rails but I'm book educated by now (which apparently

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.