Sample Image Madresah Code Snippets Contact About
TCP Interface

TCP IP Interface

Introduction

This example shows how you can use TCP .NET library to communicate between multiple clients and/or servers, by using network IP Address and port number.


Sample Image Sample Image
Fig 1: Shows layout of TCP Listener (server) Fig 2: Shows layout of TCP Client


Application was written in WPF .NET framework, with Model-View-View-Model (MVVM) pattern.
Sample Image

View Model base class
View Model base class contains all common logic required to notify client when a property has changed. This is done by using INotifyPropertyChanged interface.

The Class also uses CallerMemberName attribute, calls to the NotifyPropertyChanged, GetValue, and SetValue methods don’t have to specify property name as a string argument



Ping Network
Network topology can determine whether Ping can successfully contact a remote host. The presence and configuration of proxies, network address translation (NAT) equipment, or firewalls can prevent Ping from succeeding. A successful Ping indicates only that the remote host can be reached on the network; the presence of higher level services (such as a Web server) on the remote host is not guaranteed.

Following method shows how to determine whether a remote computer is accessible over the network.


TCP Listener (server)

Sample Image
Listener or server sockets open a port on the network and then wait for a client to connect to that port. Although other network address families and protocols exist, this example shows how to create remote service for a TCP/IP network.

The unique address of a TCP/IP service is defined by combining the IP address of the host with the port number of the service to create an endpoint for the service. The Dns class provides methods that return information about the network addresses supported by the local network device. When the local network device has more than one network address, or if the local system supports more than one network device, the Dns class returns information about all network addresses, and the application must choose the proper address for the service.

Following method shows how to create a TCP listner using Socket.



TCP Client
Sample Image

The following example program creates a client that connects to a server. The client is built with a synchronous socket, so execution of the client application is suspended until the server returns a response. The application sends a string to the server and then displays the string returned by the server on the console.




Download TCP/IP Application