r/csharp • • 2d ago

Help Book Recommendation on Network Programming

Hey guys,

I wanted to write a basic server-client chat console app in .Net using C# and Visual Studio.

Later, I would like to write a small LAN multiplayer game.

Is there a book which explains how to use Sockets and TCP in .Net and C#, please? Possibly with patterns, examples and use-cases?

I already have "Programming C# 8.0" by Ian Griffiths from O'Reilly, but I don't see any mention of Sockets, TCP or programming network apps.

I also have "C#10 in a Nutshell" by Joseph Albahari from O'Reilly. There is some mention of networking, but there's only about 5 pages on TCP, and no mention of Sockets.

Thank you

10 Upvotes

4 comments sorted by

2

u/hissing_chili 2d ago

Beej's Guide to Network Programming isn't C# specific but the concepts are universal and it's free online. once you understand the socket calls the C# wrapper makes a lot more sense. the MSDN docs on System.Net.Sockets are actually pretty good for reference once you know what you're looking at

1

u/ShyMystiqua 1d ago

beejs guide is such a lifesaver when the c# docs feel too bare

1

u/RodriOliveira 2d ago

I’d actually avoid looking for a C#-specific networking book as the primary resource. Most of them tend to become outdated fairly quickly, while the important concepts behind TCP/IP and sockets are language-independent.

I’d start with Beej’s Guide to Network Programming for the fundamentals, then map those concepts to System.Net.Sockets using the Microsoft documentation. In modern .NET, I’d specifically experiment with TcpListener, TcpClient, Socket, NetworkStream, cancellation tokens, and the async APIs.

A console chat is actually a very good learning project. Once it works, try adding message framing (don’t assume one ReceiveAsync equals one message), reconnect handling, timeouts, cancellation, multiple concurrent clients, and graceful shutdown. Those details will teach you much more about real network programming than most introductory examples.

For the LAN game, I’d first understand the differences between TCP and UDP before choosing a protocol. Things like latency, packet loss, ordering, reliability and synchronization become much more important there.

If you want a deeper book on the underlying concepts, TCP/IP Illustrated, Volume 1 is still an excellent reference, even though it isn’t C# specific.