132
|
1 /*******************************************************************************
|
|
2
|
|
3 Shows how to create a basic socket client, and how to converse with
|
|
4 a remote server. The server must be running for this to succeed
|
|
5
|
|
6 *******************************************************************************/
|
|
7
|
|
8 private import tango.io.Console;
|
|
9
|
|
10 private import tango.net.SocketConduit,
|
|
11 tango.net.InternetAddress;
|
|
12
|
|
13 void main()
|
|
14 {
|
|
15 // make a connection request to the server
|
|
16 auto request = new SocketConduit;
|
|
17 request.connect (new InternetAddress ("localhost", 8080));
|
|
18 request.output.write ("hello\n");
|
|
19
|
|
20 // wait for response (there is an optional timeout supported)
|
|
21 char[64] response;
|
|
22 auto size = request.input.read (response);
|
|
23
|
|
24 // close socket
|
|
25 request.close;
|
|
26
|
|
27 // display server response
|
|
28 Cout (response[0..size]).newline;
|
|
29 }
|