开发者

How to pass data as XML via sockets?

I want to exchange data in the form of XML schema between socket programs written in C/C++. Could someone p开发者_开发百科lease provide links tutorials which describe the process of exchanging XML schema between socket programs.

I have two software tools running in different Operating Systems, in which I coupled with socket programs written in c/c++. As both work with XML, I want to know if there is a simple way to exchange data in the form of XML documents in order to run simulation studies.

Thanks in advance.


the question is how to send xml schema through a socket program written in C/C++ ? here is an exp:

----- xml ---

...

<xs:element name="zone">

<xs:complexType>

<xs:sequence>

<xs:element name="Var_name" type="xs:string"/>

<xs:element name="var_value" type="xs:decimal"/>

</xs:sequence>

</xs:complexType>

</xs:element>

------ C/C++ ----

...

// send message to server

if (send(csocket, buffer_snd, BUFSIZE, 0) > BUFSIZE)

cout << send() failed << endl;

...

Thanking you in advance for your help,


You might consider using an XML parsing library with a streaming parser for this, assuming you can rely on the documents being well-formed on both ends - well-formed XML is self-delimiting. Something like libxml2 should be suitable.


It seems what you want is to specify your protocol in XML Schema and then auto-generate C++ classes that would allow you to parse and serialize the XML messages. If so then you may want to take a look at CodeSynthesis XSD which is an XML Schema to C++ compiler. It does pretty much exactly what you are looking for. If you want a more lighter-weight version, there is also XSD/e which is geared more towards mobile/embedded development.


Obviously, gSOAP contains relevant code, not sure if that's what you're looking for, though.


Look at how HTTP does this - simple header that indicates length of the payload that follows, plus some extras like timestamps and types. All you need to tell the other side is how many bytes to read from the socket and maybe the file name. You might also want to implement an acknowledgement back to the sender depending on your application needs.


you can use expact library, this is a good xml parser, which can create xml object and can be send

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜