none
Client, Server, Testapplication xml messages

    Question

  • Hello Forum,
    How I can send and analyze an XML message?
    My task is to send and receive such messages via socket.
    Client 127.0.0.1, Port 33
    Server 127.0.0.1
    From time to time, the server can send a status message to the client at any time.  (Full Duplex, Event, async)
    That is also difficult.
    Is there a pattern example of this requirement?
    Sometimes a message is checked with "\n\r" as end criterion
    But how do I achieve this with XML?
    <control   // begin element
      </control>  // end element to check it?
      But what about the declaration?
     
    Or can it be that if I convert a string into a stream, is it always sent completely?
      It is not possible that this is sent in parts?
     
    Thank you very much for an example and your help.
    With best regards Markus.
    Request
    <?xml version="1.0" encoding="UTF-8"?>
    <control xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..\..\ZVEI-XSD\control-1.1.xsd" locale="english" senderID="Hostname-Company-Software-Version">
    	<controlRequest requestID="20061027-080000-127" equipment="Labelingmachine-1" operation="Labeling" order="order-123" material="" requesttime="2006-10-27T08:00:00+02:00">
    		<properties>
    			<orderProperties>
    				<orderProperty name="TRACE"/>
    				<orderProperty name="NOMINALVALUE"/>
    			</orderProperties>
    			<operationProperties>
    				<operationProperty name="ACTUALVALUE"/>
    				<operationProperty name="REJECTVALUE"/>
    			</operationProperties>
    		</properties>
    	</controlRequest>
    </control>
    
    Response NOK
    <?xml version="1.0" encoding="UTF-8"?>
    <control xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..\..\ZVEI-XSD\control-1.1.xsd" locale="english" senderID="Hostname-Company-Software-Version">
    	<controlResponse responseToRequestID="20061027-080000-127" equipment="Labelingmachine-1" operation="Labeling" order="order-123" material="product-1" responsetime="2006-10-27T08:00:01+02:00" state="nok" description="Could not find operationProperty ACTUALVALUE for order order-123 in the database!">
    		<properties>
    			<orderProperties>
    				<orderProperty name="TRACE" value="true" state="ok"/>
    				<orderProperty name="NOMINALVALUE" value="1000" UnitOfMeasure="pcs" state="ok"/>
    			</orderProperties>
    			<operationProperties>
    				<operationProperty name="ACTUALVALUE" value="" state="nok"/>
    				<operationProperty name="REJECTVALUE" value="1" UnitOfMeasure="pcs" state="ok"/>
    			</operationProperties>
    		</properties>
    	</controlResponse>
    </control>
    
    Response OK
    <?xml version="1.0" encoding="UTF-8"?>
    <control xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..\..\ZVEI-XSD\control-1.1.xsd" locale="english" senderID="Hostname-Company-Software-Version">
    	<controlResponse responseToRequestID="20061027-080000-127" equipment="Labelingmachine-1" operation="Labeling" order="order-123" material="product-1" responsetime="2006-10-27T08:00:01+02:00" state="ok">
    		<properties>
    			<orderProperties>
    				<orderProperty name="TRACE" value="true" state="ok"/>
    				<orderProperty name="NOMINALVALUE" value="1000" UnitOfMeasure="pcs" state="ok"/>
    			</orderProperties>
    			<operationProperties>
    				<operationProperty name="ACTUALVALUE" value="137" UnitOfMeasure="pcs" state="ok"/>
    				<operationProperty name="REJECTVALUE" value="1" UnitOfMeasure="pcs" state="ok"/>
    			</operationProperties>
    		</properties>
    	</controlResponse>
    </control>
    

    Saturday, February 03, 2018 1:53 PM

All replies

  • Hi Markus Freitag,

    >>Or can it be that if I convert a string into a stream,

    Yes, you need convert xml string to steam, then send the stream to server.

    >>is it always sent completely? It is not possible that this is sent in parts?

    I would suggest that you could verify the stream and check if it send completely.

    Here is a complete sample about client and server, which using socket to send/receive.

    https://gist.github.com/leandrosilva/656054

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 05, 2018 9:32 AM
    Moderator
  • Hi,
    Yes not bad but not really good for me.
    Maybe you have or do you know an example to exchange XML messages.
    How do we make sure that everything has been received.
    If the server is shutdown, the client should automatically try to reconnect.

    Thank you for your help.

      Regards Markus

    Thursday, February 08, 2018 6:07 PM
  • Hi Markus Freitag,

    >>How do we make sure that everything has been received.If the server is shutdown, the client should automatically try to reconnect.

    I would suggest that you could add additional information before you send xml to server, such as the length of xml. when you receive the message, you could check if everything has been received via the length of xml.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 09, 2018 1:28 AM
    Moderator
  • Hi Markus,

    Zhanglong's suggestion about additional information is right. I'm going to make it more specific.

    You can divide one message into two parts: header and body. Body is the message you want to send, in your scenario is xml text. Header is used to provide additional information, e.g. length of your message body. You can define the first x(for example 10) bytes of your message as header and the left is body. Message id, body length and other information can be contained in header.

    You can also classify your messages into two categories: primary and secondary, one is the first message of a session and the other is the response. You can use this to guarantee that all messages are received. 

    Best Regards,

    Charles He


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, February 09, 2018 3:31 AM
  • Hi Zhanglong Wu,
       Charles He21,

    Thanks for your answer.
    >I would suggest that you could add additional information before you send xml to server,
    >such as the length of xml. when you receive the message, you could check if everything
    >has been received via the length of XML.
    Request
    <?xml version="1.0" encoding="UTF-8"?>
    <control xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..\..\ZVEI-XSD\control-1.1.xsd" locale="english" senderID="CompanyAir">
     <controlRequest requestID="20061027-080000-127" equipment="machine-1" operation="Labeling" order="order-123" material="" requesttime="2018-02-09T08:00:00+02:00">
     .....
     .....
     </controlRequest>
    </control>

    Yes, or
    I take the first element and read until I find the last element.
    How do I get the first item?
    What if the last element never comes?
    My big request is, do not you have a complete example of how to do that?
    I think that many users may need in the forum.

    Thanks in advance.
    With best regards Markus

    Friday, February 09, 2018 5:37 PM
  • Hi Markus,

    If you send all your elements in several sessions, you can set an end flag in header to indicates that all elements have been sent. What's more, you can set a timeout at server end and send an error message to the client when end flag not comes in a timeout.

    I want to emphasize that it's never a simple and easy thing to define a protocol(just what you want to do , I think), you must take lots of things into consideration: message type definition, timeout handling, duplicate messages handling and so on. I know an interface protocol based on socket, SECS/GEM, that's semiconductor industry protocols used when communicating with semiconductor equipment via socket.

    To simplify, I think you can send a message in one session and add some additional information to ensure that message is sent correctly and completely, these additional information may contain check sum of your message and total length of your message.

    Best Regards,

    Charles He


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.




    Saturday, February 10, 2018 2:22 PM
  • Hello,

    Yes, it is really difficult and you will not find a complete example on the internet.

    • - Send and receive XML messages
      - Reconnect
      - Keep Alive Messages
      - Timeout
      I do not know, is still a common problem, task.
    Maybe you know an understandable example project.
    Thanks in advance.

    With best regards Markus

    Monday, February 12, 2018 5:36 PM
  • Hi Markus,

    Sorry about not finding an understandable example for you. I notice that you have posted several threads about XML parsing and delivering, like this one. Are they all in one project? Is your project related to PCB system? Can you describe specifically about your project? What are the functions of your client and server? Are your client and server all PCs? Based on these information, we can have a concrete discussion.

    Best Regards,

    Charles He


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 21, 2018 8:14 AM