C# - 17 - Network communication

[C# 3.5]

Here are two simple console programs to demonstrate communication over a network (using sockets and network streams).

First there is the 'server' side:

Then there is the client side:

Both sides are similar, except the server uses TcpListener to wait for an incoming connection from a client, and the client uses TcpClient to establish a connection with a waiting server. In both cases you must add a reference to System.Net to the project. On the client side remember to replace localHost with the name of the server you wish to connect with.

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License