O'Reilly logo

D Cookbook by Adam D. Ruppe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a network client and server

Networking is a common requirement in modern applications. Phobos offers a module, std.socket, which provides a foundation for networked applications. We'll write a client and server pair to demonstrate how to use it. The client will send lines from standard input to the server. The server will accept any number of connections, say hello to new clients, and then echo back whatever it received.

How to do it…

We'll be building two separate applications: the client and the server.

Client

Let's create a client by executing the following steps:

  1. Create a Socket object.
  2. Connect to the server.
  3. Declare a buffer to hold the received data. The buffer must be preallocated to the maximum amount of data you want to handle in a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required