Answered by:
Sample Client, TCP-Socket

Question
-
Hi,
I have to implement a client in an existing C++/MFC application and send XML telegrams.
Do you have a sample code.
If no response is received within 2 seconds, error message.<ROOT>
<ORDER_REQ state="?" /></ROOT>
//-----
<ROOT>
<ORDER_RES current="030121521993100000001000" />
</ROOT>Thanks in advance.
Best regards Markus.
Wednesday, August 5, 2020 11:53 AM
Answers
-
Hi,
>>Do you know an entire sample project?
With requests, answers and timeout, very much with automatic reconnection.As far as I'm concerned you could get plenty examples at codeproject.com, codeguru.com, and even more available through your favorite search engine. If you've got specific errors, you could post here, and we will provide you with better help.
Best Regards,
Jeanine Zhang
"Visual c++" forum will be migrating to a new home on Microsoft Q&A !
We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A !
For more information, please refer to the sticky post.- Marked as answer by Markus Freitag Thursday, August 13, 2020 7:50 AM
Wednesday, August 12, 2020 7:02 AM
All replies
-
Hi,
Thank you for posting here.
>>I have to implement a client in an existing C++/MFC application and send XML telegrams.
MFC supplies two models for writing network communications programs with Windows Sockets. They are CAsyncSocket and CSocket. For more details you could refer to the Doc:https://docs.microsoft.com/en-us/cpp/mfc/windows-sockets-in-mfc?view=vs-2019
To create a Client socket, first of all we need to declare a variable of type CAsyncSocket or our own class derived from CAsyncSocket or CSocket. Then we should call the create() function.
CAsyncSocket sock; sock.Create(); // Use the default parameters
Because the socket is a client, we should use CAsyncSocket::Connect to connect the socket object to the server socket.
And then we could use CAsyncSocket::Send to send data on a connected socket.
I suggest you could refer to the link: https://docs.microsoft.com/en-us/cpp/mfc/windows-sockets-using-class-casyncsocket?view=vs-2019
Best Regards,
Jeanine Zhang
"Visual c++" forum will be migrating to a new home on Microsoft Q&A !
We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A !
For more information, please refer to the sticky post.Thursday, August 6, 2020 5:56 AM -
Hi,
- there is a complete example that sends and receives XML messages. Read until the root element is complete?
Once in sync.
Asynchronous with timeout.
Thanks for tipps.
Greetings Markus.
Next time i take the new forum, although this one is better for publishing code snippets. This is not always possible in the new forum.
Thursday, August 6, 2020 6:53 AM - there is a complete example that sends and receives XML messages. Read until the root element is complete?
-
Hi,
I suggest you may refer to the link: https://stackoverflow.com/questions/9473235/reading-an-xml-file-in-a-c-program
Best Regards,
Jeanine Zhang
"Visual c++" forum will be migrating to a new home on Microsoft Q&A !
We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A !
For more information, please refer to the sticky post.Friday, August 7, 2020 9:22 AM -
Hi,
Do you know an entire sample project?
With requests, answers and timeout, very much with automatic reconnection.
Thanks in advance.
Best Regards,
Markus
Monday, August 10, 2020 1:34 PM -
Hi,
>>Do you know an entire sample project?
With requests, answers and timeout, very much with automatic reconnection.As far as I'm concerned you could get plenty examples at codeproject.com, codeguru.com, and even more available through your favorite search engine. If you've got specific errors, you could post here, and we will provide you with better help.
Best Regards,
Jeanine Zhang
"Visual c++" forum will be migrating to a new home on Microsoft Q&A !
We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A !
For more information, please refer to the sticky post.- Marked as answer by Markus Freitag Thursday, August 13, 2020 7:50 AM
Wednesday, August 12, 2020 7:02 AM