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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:45:22+00:00 2026-05-13T23:45:22+00:00

I’m trying to write a client-server application in Java with an XML-based protocol. But

  • 0

I’m trying to write a client-server application in Java with an XML-based protocol.
But I have a great problem!

See this part of client code:

InputStream incoming = skt.getInputStream(); //I get Stream from Socket.
OutputStream out = skt.getOutputStream();

[...]

XMLSerializer serializer = new XMLSerializer();
//This create an XML document.
tosend = WUTPClientWriter.createMessage100(projectid, cpuclock, cpunumber);
serializer.setOutputByteStream(out);
serializer.serialize(tosend);

At this point server fall in deadlock. It wait for EOF but I can’t send it because if I use

out.close();

or

skt.shutdownOutput();

I close the Socket and I must keep this connection alive.

I can’t send ‘\0’ becouse I get Parse Error in the server.

How can I do it? Can I “close” the output stream without closing the socket?

RESOLVED
I’ve created new class XMLStreamOutput and XMLStreamInput with advanced Stream gesture.

  • 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-13T23:45:23+00:00Added an answer on May 13, 2026 at 11:45 pm

    I’ve resolved with this four class:

    1)

    public class XMLOutputStream extends  ByteArrayOutputStream {
    
     private DataOutputStream outchannel;
    
     public XMLOutputStream(OutputStream outchannel) {
         super();
         this.outchannel = new DataOutputStream(outchannel);
     }
    
     public void send() throws IOException {
         byte[] data = toByteArray();
         outchannel.writeInt(data.length);
         outchannel.write(data);
         reset();
     }
    }
    

    2)

    public class XMLSender {
    
     public static void send(Document tosend, OutputStream channel) throws   TransformerConfigurationException, IOException {
         XMLOutputStream out = new XMLOutputStream(channel);
    
         StreamResult sr = new StreamResult(out);
         DOMSource ds = new DOMSource(tosend);
         Transformer tf = TransformerFactory.newInstance().newTransformer();
    
         try {
             tf.transform(ds, sr);
         } catch (TransformerException ex) {
             Logger.getLogger(XMLSender.class.getName()).log(Level.SEVERE, null, ex);
         }
    
         out.send();
     }
    }
    

    3)

    public class XMLInputStream extends ByteArrayInputStream {
    
     private DataInputStream inchannel;
    
     public XMLInputStream(InputStream inchannel) {
         super(new byte[2]); 
         this.inchannel = new DataInputStream(inchannel);
     }
    
     public void recive() throws IOException {
         int i = inchannel.readInt(); 
         byte[] data = new byte[i];
         inchannel.read(data, 0, i); 
         this.buf = data; 
         this.count = i;
         this.mark = 0;
         this.pos = 0;
     }
    
    }
    

    4)

    public class XMLReceiver {
    
     public static Document receive(InputStream channel) throws ParserConfigurationException, TransformerConfigurationException, IOException, SAXException {
    
         DocumentBuilderFactory docBuilderFact = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = docBuilderFact.newDocumentBuilder();
         Document request = null;
    
    
         XMLInputStream xmlin = new XMLInputStream(channel);
    
         xmlin.recive();
    
         request = docBuilder.parse(xmlin);
    
         return request;
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.