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

The Archive Base Latest Questions

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

Hello Experts can somebody please indentify the problem with this server why this is

  • 0

Hello Experts
can somebody please indentify the problem with this server why this is unable to connect more then one client

import java.io.*;
import java.net.*;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.*;

public class MultithreadedServer extends Thread {

    private ServerSocketChannel ssChannel;

    private Thread tRunSer = new Thread(this, "ServerSelectThread");

    public static void main(String argv[]) throws Exception {
        new MultithreadedServer();
    }

    public MultithreadedServer() throws Exception {
        this.start();
    }

    public void run() {
        while (true) {
            try {

                ssChannel = ServerSocketChannel.open();
                ssChannel.configureBlocking(false);
                int port = 2345;
                ssChannel.socket().bind(new InetSocketAddress(port));
            } catch (Exception e) {
            }
        }
    }
}

class Connect extends Thread {
    private ServerSocketChannel ssChannel;
    private SimManager SM;
    private BallState BS = new BallState(10, 5);

    public Connect(ServerSocketChannel ssChannel) {
        this.ssChannel = ssChannel;

        SM = new SimManager(BS);
        SM.start();
    }

    public void run() {
        try {
            SocketChannel sChannel = ssChannel.accept();
            while (true) {
                ObjectOutputStream oos = new ObjectOutputStream(sChannel
                        .socket().getOutputStream());
                oos.writeObject(BS);
                System.out.println("Sending String is: '" + BS.X + "'" + BS.Y);
                oos.flush();

            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

my intention is to send the objects on network.

please help

new code:

import java.io.*;
import java.net.*;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.*;

public class MultithreadedServer extends Thread {

    private ServerSocketChannel ssChannel;
    private SimManager SM;
    private BallState BS = new BallState(10, 5);
    private Thread tRunSer = new Thread(this, "ServerSelectThread");

    public static void main(String argv[]) throws Exception {
        new MultithreadedServer();
    }

    public MultithreadedServer() throws Exception {
        this.start();
    }

    public void run() {
        // create the server socket once
        try {
            ssChannel = ServerSocketChannel.open();
            ssChannel.configureBlocking(false);
            ssChannel.socket().bind(new InetSocketAddress(2345));
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        while (true) {
            // accept new connections on the socket

            SocketChannel accept;
            try {
                accept = ssChannel.accept();
                ObjectOutputStream oos;
                oos = new ObjectOutputStream(accept.socket().getOutputStream());

                oos.writeObject(BS);
                System.out.println("Sending String is: '" + BS.X + "'" + BS.Y);
                oos.flush();

            }

            catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
  • 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-21T09:16:24+00:00Added an answer on May 21, 2026 at 9:16 am

    You are creating a new server socket for each loop iteration (using the same port over and over). You must create the server socket only once, and then accept new incoming connections.

    Something like:

     public void run() {
        // create the server socket once
        ssChannel = ServerSocketChannel.open();
        ssChannel.configureBlocking(false);
        ssChannel.socket().bind(new InetSocketAddress(2345));
    
        while (true) {
            // accept new connections on the socket
            try {
                SocketChannel accept = ssChannel.accept();
                System.out.println("new client: " + accept.getRemoteAddress());
            } catch (Exception e) {
                System.out.println("exception: " + e.getMessage());
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can some one please tell me the problem with this code. I am reading
Hello I see contradicting definitions. Android experts, can you explain this to me please?
Hello can anybody solve this please I'm creating the object in the action class
Hello SQL Server engine experts; please share with us a bit of your insight...
Hello everyone please help me out regarding this query which is fetching the data
For example: mytuple = (Hello,World) def printstuff(one,two,three): print one,two,three printstuff(mytuple, How are you) This
Hello Experts i have A Sp , which Contains lot of if/else Condition Please
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello we have an SQL server application running over a low bandwith connection. We
Hello StackOV experts! I've just completed the core pieces of my first MVC3 site.

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.