Let me elaborate on the explanation with an example (with snippets taken from here).
You're not going to be successful thinking of the XML you receive like
a file, which is where your Unexpected end of file has occurred error
is coming from. You must parse the XML incrementally.
When you connect to an XMPP, you open a connection to the server. To do this, you send something like the following...
<stream:stream
to='example.com'
xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'
version='1.0'>
...let's ignore authentication for the moment and just assume that this works. You'll notice that this one section alone is not valid XML (the element is not closed). However, for XMPP, that's okay. The server will send back it's own messages to tell you that you're good to go. Now we know that we can send our message stanzas. We type out our message, then send...
<message from='juliet@example.com' to='romeo@example.net'>
<body>Romeo, romeo...</body>
</message>
After a few seconds, we decide to go offline...
<presence type='unavailable'/>
</stream:stream>
Now let's look at what we sent...
<stream:stream
to='example.com'
xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'
version='1.0'>
<!-- A few seconds elapsed -->
<message from='juliet@example.com' to='romeo@example.net'>
<body>Romeo, romeo...</body>
</message>
<!-- A few seconds elapsed -->
<presence type='unavailable'/>
</stream:stream>
So, in the end, you can think of the interaction with the server as if you are creating a document that EVENTUALLY becomes a fully valid XML document. And this is a nice way to think about things when you're first learning about XMPP.
However, you're creating this document over a period of time, not all at once. XML libraries typically don't think that you're only going to create PART of the document now: they're concerned with creating the entire document at once. This is why traditional XML libraries may not be helpful for you in writing XMPP programs. Additionally, a simple XML library won't be able to deal with extra information such as authentication logic.
In the end, you COULD write your own library. However, you would need to be very careful in your selection of tools (as like I said before, XML libraries might not be able to handle these partial XML creations).
Anyway, in the end, your question is...
How can I send not closed pice of xml?
And the answer is: find a library to do it for you. And I don't mean just the XML parts: I mean all of XMPP. The right library will not even need you to concern yourself with the fact that XML even exists unless you get really advanced. If you can't find a library...
- Look harder. Spending a day looking for a library is STILL less time than a month making your own.
- See if you can find an open-source library that does most of what you want. Then, work around the parts that are different, or make your own source code changes to fill in the gaps.