Server/Client TCP/IP Sample

Noah Aas 1,210 Reputation points
2025-10-23T17:10:14.88+00:00

The goal:
I create two C# desktop WPF applications. Two applications each.

  • One server
  • One client

The exchange should take place via TCP/IP. Messages must be transmitted in both directions. Question Answer. When an application is closed and reopened, a connection should follow automatically.
Do you have any good ideas or examples with TcpClient and TcpListener library?
I see the following challenge.
The user interface and the automatic connection. Ideally, I should be able to see in the user interface what has been sent, what has been received, and whether the connection is active.

enter image description here

Developer technologies | C#
Developer technologies | 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.
{count} votes

Answer accepted by question author
  1. Bruce (SqlWork.com) 82,146 Reputation points Volunteer Moderator
    2025-10-24T16:25:16.9766667+00:00

    Because it client / server, the client always connects to the server.

    the client needs a loop. When it tries to connect it may fail. The client should delay and try again. When connected, it may lose the connection, so it should go back to the connect loop.

    the server just waits for a connection. If the connection is lost, it goes back to waiting.

    both the client and need to keep track of the connection status. If live they can send a message, if not then wait until the connection is restored. Detecting lost connection will typically happen on a message send. App often implements a ping/keep alive message they send to more quickly detect a lost connection .


0 additional answers

Sort by: Most helpful

Your answer

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