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

  • Home
  • SEARCH
  • 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 8296701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:07:25+00:00 2026-06-08T15:07:25+00:00

Hello guys have client server chat and i try to write load test on

  • 0

Hello guys have client server chat and i try to write load test on it. i use my protocol it looks like XMPP. I send XML and parse it. If I start the server, for some users it works properly. But I have am load-testing and am starting a lot of users and sending messages from each one. In the test I do not create new client, i’m only instantiating an output thread with an output stream and sending messages using it. The server sends a message that it recieved to all users, so I create one user that listens to the other users. And sometimes I recieve the exception: Software caused connection abort: recv failed This is my console:

06:55:49 Guest 9 (online)  says : Hello Server. Message number^4
06:55:49 Guest 9 (online)  says : Hello Server. Message number^5
06:55:49 Guest 11 (online)  says : Hello Server. Message number^0
06:55:49 Guest 4 (online)  says : Hello Server. Message number^6
ERROR ServerThread - Error in reading from stream: java.net.SocketException: Software caused connection abort: recv failed
ERROR ServerThread - Error in reading from stream: java.net.SocketException: Software caused connection abort: recv failed
06:55:49 Guest 9 (online)  says : Hello Server. Message number^6

This is my serverThread. I skip the part where it is waiting for users.

public class ServerThread implements Runnable {
    private static final Logger LOG = Logger.getLogger(ServerThread.class);
    private XMLProtocol protocol;
    private Socket socket;
    private BufferedReader input;
    private PrintWriter out;
    private static Date date;
    private String username;
    private String status = "online";
    private SimpleDateFormat dateFormat;
    private String buffer = "";
    private JAXBContext jaxbContext;
    private Unmarshaller jaxbUnmarshaller;

    public ServerThread(Socket s) throws SAXException, IOException, JAXBException {
        input = new BufferedReader(new InputStreamReader(s.getInputStream()));
        jaxbContext = JAXBContext.newInstance(XMLProtocol.class);
        out = new PrintWriter(s.getOutputStream());
        username = "Guest " + Server.getUserCounter();
        dateFormat = new SimpleDateFormat("hh:mm:ss");
        Server.addUser(username, out);
        date = new Date();
        socket = s;
        new Thread(this);
    }

    public void run() {

        try {
            while (true) {
                if (input.ready()) {
                    if (buffer.length() <= 256) {
                        if ((buffer = input.readLine()).toString().endsWith("</XMLProtocol>")) {

                            protocol = new XMLProtocol();
                            jaxbUnmarshaller = jaxbContext.createUnmarshaller();
                            protocol = (XMLProtocol) jaxbUnmarshaller.unmarshal(new StreamSource(new StringReader(buffer)));

                            switch (ChatCommands.valueOf(protocol.getStatus())) {
                            case LOGIN: {
                                Server.sendToAll(Server.buildResponce("User: " + this.username + " Has been changed nickname on "
                                        + protocol.getContent()));
                                this.username = protocol.getContent();
                                break;
                            }
                            case STATUS: {
                                Server.sendToAll(Server.buildResponce("The user: " + this.username + " Is now:" + protocol.getContent()));
                                this.status = protocol.getContent();
                                break;
                            }
                            case LOGOUT: {
                                Server.sendResponce(Server.buildResponce(ResponseCommands.DISCONNECT), out);
                                quit();
                                break;
                            }
                            default: {
                                LOG.trace("Getting message from user: " + username + " recived message: " + protocol.getContent());
                                date = Calendar.getInstance().getTime();
                                Server.sendToAll(Server.buildResponce(dateFormat.format(date.getTime()) + " " + username + " ("
                                        + this.status + ") " + " says : " + protocol.getContent()));
                                break;
                            }
                            }
                        }
                    } else {
                        Server.sendResponce(Server.buildResponce(ResponseCommands.SENDING_FAILED), out);
                    }
                }
            }

        } catch (IOException e) {
            LOG.error("Error in reading from stream: " + e);
        } catch (JAXBException e) {
            LOG.error("Error in Marshalling: " + e);
        } finally {
            try {
                Server.sendResponce(Server.buildResponce(ResponseCommands.UNEXPECTED), out);
                quit();
                LOG.trace("Socket closed");
            } catch (IOException | JAXBException e) {
                LOG.error("Socket no closed" + e);
            }
        }
    }

    public void quit() throws IOException, JAXBException {
        Server.sendToAll(Server.buildResponce("User: " + this.username + " quited"));
        Server.removeUser(out);
        socket.shutdownInput();
        socket.shutdownOutput();
        socket.close();
    }
}

And this is my test

public class ServerLoadTest {

    private static ExecutorService exec = Executors.newFixedThreadPool(1000);
    private static Socket s[] = new Socket[50];// = new Socket();

    public static void main(String[] args) throws JAXBException, UnknownHostException, IOException, InterruptedException,
            XMLStreamException, ParserConfigurationException, SAXException {
        exec.execute(new TestServerThread()); // start Server thread
        Thread.sleep(500); // wait till Server starts.

        s[0] = new Socket("localhost", 4444);

        exec.execute(new InputThread(s[0], new BufferedReader(new InputStreamReader(s[0].getInputStream())))); // Start
                                                                                                                // one
        for (int i = 0; i < 20; i++) {
            exec.execute(new TestClientThread());           
        }
    }

}

class TestClientThread implements Runnable {
    private static final Logger LOG = Logger.getLogger(TestClientThread.class);
    private XMLProtocol protocol;
    private JAXBContext jaxbContext;
    private Marshaller jaxbMarshaller;
    private Socket socket;
    private OutputStream outputStream;

    public TestClientThread() throws JAXBException, UnknownHostException, IOException, InterruptedException, XMLStreamException,
            ParserConfigurationException, SAXException {
        jaxbContext = JAXBContext.newInstance(XMLProtocol.class);
        jaxbMarshaller = jaxbContext.createMarshaller();
        socket = new Socket("localhost", 4444);
        protocol = new XMLProtocol();
        outputStream = socket.getOutputStream();

        new Thread(this);

    }

    @Override
    public void run() {
        try {

            for (int i = 0; i < 10; i++) {
                protocol.setContent("Hello Server. Message number^" + i);
                protocol.setStatus(ChatCommands.MSG.getCommandCode());
                jaxbMarshaller.marshal(protocol, outputStream);
            }
            protocol.setContent("Hello Server. Message number^");
            protocol.setStatus(ChatCommands.LOGOUT.getCommandCode());
            jaxbMarshaller.marshal(protocol, outputStream);


/*          socket.shutdownInput();
            socket.shutdownOutput();
            socket.close();
            Thread.currentThread().interrupt();*/

        } catch (JAXBException  e) {
            LOG.trace("Error in marshaling ");

        }
    }
}

class TestServerThread implements Runnable {
    private Server server;

    public TestServerThread() {
        new Thread(this);
    }

    @SuppressWarnings("static-access")
    @Override
    public void run() {
        try {
            server.main(null);
        } catch (IOException | JAXBException | ParserConfigurationException | SAXException e) {
            Assert.assertFalse(false);
        }
    }
}
  • 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-06-08T15:07:27+00:00Added an answer on June 8, 2026 at 3:07 pm

    I got these errors in the past too.
    I think, that these errors caused by a non synchronized resource. But I couldnt find something in the javadoc that points me to an mistake.

    So I decided to use jersey/grizzly for connection handling, data encoding etc.
    If you’re interessted in, read my comment there: MultiClient / Server. Handle communications

    But, I would appreciated, if someone can tell us how to use plain old sockets in a heavy concurrent environment.

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

Sidebar

Related Questions

Hello guys sorry if the question looks stupid to you. i have 3 tables
Hello guys I have a map like this http://sinanisler.com/demo/map/ and as you can see
hello guys i have three server and i mange it from SSH so i
Hello guys i have a problem while trying to use the 'radio' input in
Hello guys I have a Model with field DateTime like: include Mongoid::Document include Mongoid::MultiParameterAttributes
Hello guys I have a question regardless a old code a client needed a
Hello guys i have installed wamp server Version 2.0 .. and i have tried
Hello guys i have dataform in silverlight 4 project item source is: ItemsSource={Binding Data,
Hello guys, I have been trying to implement the DSUM function but failed to
Hello Guys! I started learning python GUI development. Let's say I have this script:

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.