C# TcpClient/TcpListener / Full Duplex Communication / Sample

Markus Freitag 3,791 Reputation points
Feb 1, 2023, 5:23 PM

Hello!

I have already asked. There must be a good example of Socket, TcpClient, TcpListener that does the following.

  • Duplex operation between client and server
  • Automatic reconnection
  • On 10 failed attempts, error message.
  • Read until the root element is received.
  • Read until the element root has been received, if necessary buffer it in a processing list and process it bit by bit

Send from Server to Client or the other way around.

<ROOT>
  <REQUESTS>
    <VARIANT name="TEST01022034">
      <PROGRAM name="87.1554.0_87.1554.0" />
    </VARIANT>
    <VARIANT name="TEST01022023">
      <PROGRAM name="99.884.0_M" />
      <PROGRAM name="99.884.0_MR" />
      <PROGRAM name="AAA_AAAAA" />
      <PROGRAM name="BBB_AAAAA" />
    </VARIANT>
  </REQUESTS>
</ROOT>

Send from Client to Server or the other way around.

<ROOT>
  <RESPONSE>
    <CURRENT name="TEST01022034">
      <PRODUCT name="Washing_machine_99.8854.0_99.8854.0" />
    </CURRENT>
   </RESPONSE>
</ROOT>

There are many small examples, 1000 variants. Is there a good working example for this use case? Thank you in advance for your help.

Windows Desktop App, WPF App or Windows Forms App. VS2017/2019

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,973 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,097 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 47,501 Reputation points Microsoft Vendor
    Feb 2, 2023, 8:36 AM

    Hi @Markus Freitag , Welcome to Q&A.

    Regarding Socket, TcpClient and TcpListener, I have written a winforms related example.

    Among them are about creating tcplistener and using tcpclient to connect.

    Please refer to this link and post an update if you have any questions.

    Best Regards, Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.