Search Forum
(57415 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


              
Printable Version

Multithreaded TCP/UDP Client Server v.1
By Patrick Lam

The Server: The simple multi-threaded TCP/UDP Server v1 provides a TCP and UDP servers running at separate threads. The sockets can receive a text messages send frm the client machine, and return a confirmation together with the received text back to the client. It uses the traditional socket programming methods (socket/bind/listen/accept). In the v2 of this program, I will make use if the .Net library's TcpListener that will make things much easier.

The Client: The simple TCP/UDP Client v2 allows users to send a simple text message to the server and get a confirm message from the server. Users can either use TCP or UDP to send this message. The program uses the traditional socket programming technique (socket/bind/connect/send). In v2 of this program, I will make use of .Net library's TcpClient and UdpClient, that will make things much easier.

To demo the program, the user has to run the server and the client on separate machines. It he/she wants to run both server and client on the same machine, the server's host name has to be the machine's host name. That is, it can't be "localhost". If "localhost" is used, there will be a socket exception. I still can't figure out why yet.

All the other required information is provided at the beginning of each file.

This post intends to be a beginner level of server/client socket programming and multi-threading demo.

Download sampleTcpUdpServer1.cs

Download sampleTcpUdpClient1.cs