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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:27:02+00:00 2026-05-26T20:27:02+00:00

Well, to be honest it works just for one client, don’t really know why.

  • 0

Well, to be honest it works just for one client, don’t really know why. Also client is receiving everything two or three times. [ I’ve used telnet as a client. When I start another telnet session, it stays, but it doesn’t give any output ].
I will add gui code if needed.

public static void main(String args[]) throws IOException {
    String s;
    initGUI();
    try {
        hostServer = new ServerSocket(port);
        socket = hostServer.accept();
        area.append(" "+socket+" connection\n");
        changeStatusTS(CONNECTED, true);
    } catch (IOException e) {
        cleanUp();
        changeStatusTS(DISCONNECTED, false);
    }
    while (true) {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            System.out.println(e);
        }
        while(true) {
            multi ml = new multi(socket);
            ml.start();
        }
    }
}

static class multi extends Thread{

    public multi(Socket c) throws IOException {
        socket = c;
    }
    public void run(){
        String s;
        switch (connectionStatus) {
            case CONNECTED:
                try {
                    in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                    out = new PrintWriter(socket.getOutputStream(), true);
                    if (toSend.length() != 0) {
                        out.print(toSend); out.flush();
                        toSend.setLength(0);
                        changeStatusTS(NULL, true);
                    }
                    if (in.ready()) {
                        s = in.readLine();
                       if ((s != null) &&  (s.length() != 0)) {
                          if(s.equals("test")==true){
                          out.print("bazinga"); 
                          out.flush();
                      }

                     if (s.equals(END_CHAT_SESSION)) {
                        changeStatusTS(DISCONNECTING, true);
                     }
                     else {
                        appendToChatBox("INCOMING: " + s + "\n");
                        changeStatusTS(NULL, true);
                     }
                  }
               }
            }
            catch (IOException e) {
               cleanUp();
               changeStatusTS(DISCONNECTED, false);
            }
            break;

         case DISCONNECTING:

            out.print(END_CHAT_SESSION); 
            out.flush();

            cleanUp();
            changeStatusTS(DISCONNECTED, true);
            break;

         default: break; 
         }
    }
    }   
    }
  • 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-26T20:27:03+00:00Added an answer on May 26, 2026 at 8:27 pm

    I’ve not looked at the entire code but an immediate problem looks to be that your server is not calling accept() in a loop. I’d change your main to be something like the following:

    public static void main(String args[]) throws IOException {
        String s;
        initGUI();
        hostServer = new ServerSocket(port);
        while (true) {
            try {
                // wait for the next client to connect
                socket = hostServer.accept();
            } catch (IOException e) {
                cleanUp();
                changeStatusTS(DISCONNECTED, false);
                break;
            }
            area.append(" " + socket + " connection\n");
            // you probably don't want this or you want this to be per client?
            changeStatusTS(CONNECTED, true);
            // start a multi thread on the accepted socket
            Multi ml = new Multi(socket);
            ml.start();
        }
    }
    

    When a client calls connection, the server’s accept() call returns and your code should create a new Multi thread to handle that connection. Then the server should loop around and call accept() again, waiting for the next client to connect.

    Hope this helps.

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

Sidebar

Related Questions

Well, this is my first post here and really enjoying the site. I have
Well, what is one?
I know this isn't a straightforward question but I would really appreciate some feedback
Well, we all know test-driven development. I'd need to write a GUI-based library, but
I am just going to be honest and say that I hate building web
Well friends, I have got this query which works but is very long for
Well, to be honest this is actually my homework where I have to implement
I just read this post about why new-line warnings exist, but to be honest
I want to access a remote SQL database for my Silverlight client. I know
Well the subject is the question basically. Are there any version control systems out

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.