question

DavidHoffman-6474 avatar image
0 Votes"
DavidHoffman-6474 asked NicoZhu-MSFT answered

C++/WinRT TCP Client question

In order to receive data from the server, do I need to place the DataReader inside a socket listener function that can call itself? Thanks.

windows-uwpc++
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you provide some more information about your project and platform?

0 Votes 0 ·

This is a very general question. The details are UWP, Windows 10, C++/WinRT. I am trying to add a TCP client to my existing code that is using WinRT Pages. I had some code that was written in C++/CX that demonstrated how to write a server and client. I stripped the server and converted to C++/WinRT and I just could not get it to work well. The problem I was having was with concurrency and not receiving my data correctly from the server that was in another program. I assumed that I had not converted it correctly, and when I reread this page interop-winrt-cx-async I found that it would be easier if I used the C# version to convert from. That is my plan now. To use the C# code to convert. So my question is generally when you use a DataReader does it need be inside a socket listener for it to work properly. The code I am converting seams to be showing exactly that. It makes sense that it would if I understand what is happening in code, but WinRT is very new to me and I just needed the clarification. Thanks.


0 Votes 0 ·

1 Answer

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT answered

Hello, Welcome to Micorosoft Q&A,

In order to receive data from the server, do I need to place the DataReader inside a socket listener function that can call itself?

Sure, you need to place DataReader in to OnConnection event and use receiving-loop block to reader InputStream for more detail please refer to code sample here.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.