Implementing Sockets

Although more focus is given today to distributed, n-tier concepts, there may still be a need for client/server computing. There are plenty of legacy systems out there and Internet utilities that require sockets.

This section shows how to create socket-based programs. It has two components: a client and a server. The server delivers quotes, and the client requests a quote and prints it to the console. When trying the programs out, bring up the server first and then start the client in a different process or window.

A Socket Server

The server program uses sockets to deliver information (quotes) to requesting clients. Listing 24.1 demonstrates how to create a server program with sockets:

Listing 24.1. Creating a Socket Server: ...

Get C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.