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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:28:02+00:00 2026-05-24T00:28:02+00:00

So, I pass data in xml via socket. When I have run server side,

  • 0

So, I pass data in xml via socket. When I have run server side, I open cmd and execute command “telnet localhost 999”. In this moment new thread are started and in this thread I pass input stream in Stax parser. On cmd I input simple xml file (copy-past from file) and this data are sending to server side and parsing correctly.

Problem it is: when my parser parses the data, it continues to wait for something. I mean, data from input stream was parsed correctly and entity for this data was filled, but the program does not pass to next step. It seems like parser wait last chracter of xml, because when I have closed cmd app passes to next step (line: “String[] commands = parser.commands;”)

Here code:

<?xml version="1.0" encoding="UTF-8" ?>
<login>
<user-name>name</user-name>
<password>password</password>
</login>


@Override
public void run() {
    try {
        try {
            InputStream is = socket.getInputStream();
            boolean complete = false;
            while (!complete) {
                // handle command was received from client
                if (is.available() == 0) {
                    continue;
                }
                Parser parser = new Parser();
                parser.parseXmlStax(is);
                String[] commands =  parser.commands;

                                    // if wrong format, send number of error end exit
                if (!checkCommands(commands)) {
                    DataOutputStream oos = new DataOutputStream(
                            socket.getOutputStream());
                    oos.writeBytes("Eror. Try again");
                    continue;
                }

public void parseXmlStax(InputStream is) throws XMLStreamException,
        IOException, ParserConfigurationException, SAXException {
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    XMLStreamReader xmlReader = xmlFactory.createXMLStreamReader(is);
    int type = xmlReader.getEventType();
    try {
        while (true) {
            switch (type) {
            case XMLStreamConstants.START_DOCUMENT:
                logger.info("Stax parsing: start document");
                break;
            case XMLStreamConstants.START_ELEMENT:
                logger.info("Stax parsing: start element");
                thisElement = xmlReader.getLocalName();
                break;
            case XMLStreamConstants.CHARACTERS:
                logger.info(String.valueOf("CHARACTERS"));
                char[] ch = xmlReader.getTextCharacters();
                int length = xmlReader.getTextLength();
                int start = xmlReader.getTextStart();

                String command = new String(ch, start, length);
                if (thisElement.equalsIgnoreCase(LoginItem.LOGIN)) {
                    commands[0] = thisElement;
                } else if (!xmlReader.isWhiteSpace()
                        && thisElement
                                .equalsIgnoreCase(LoginItem.USER_NAME)) {
                    commands[1] = command;
                } else if (!xmlReader.isWhiteSpace()
                        && thisElement.equalsIgnoreCase(LoginItem.PASSWORD)) {
                    commands[2] = command;
                }

                if (thisElement.equalsIgnoreCase(LoginItem.LOGOUT)) {
                    commands[0] = thisElement;
                    commands[1] = command;
                }

                if (thisElement.equalsIgnoreCase(LoginItem.STATUS)) {
                    commands[0] = thisElement;
                    commands[1] = command;
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                logger.info("Stax parsing: end element");
                break;
            case XMLStreamConstants.END_DOCUMENT:
                logger.info("Stax parsing: end document");
                break;
            }
            if (!xmlReader.hasNext()) {
                break;
            }
            type = xmlReader.next();
        }
    } finally {
        xmlReader.close();
    }
}
  • 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-24T00:28:03+00:00Added an answer on May 24, 2026 at 12:28 am

    I solved my issue. On client side I send data without end symbol. So I only add ‘\n’ to end of my command.
    It is worth solution, and I think that I know how to do it better. I should wrap my xml document in tag and send/response data until I get tag

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

Sidebar

Related Questions

At work we are being asked to create XML files to pass data to
What is the best way to pass data between a C server to a
I have a user control in a repeater that I need to pass data
I'm looking for secure ways to pass data between a client running Flash and
Which method would you recommend to pass data from a child view back to
What's the best way to pass data from one Windows Forms app (an office
I am using a cross page postback for Page A to pass data to
In previous releases there were 3 ways to pass data from controller to view
In a WinForms UserControl, I would pass data to the main GUI thread by
I'm so sick of the pass-callback-data-as-void*-struct anti-pattern. Boost bind solves it nicely, but is

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.