1 using System;
2 using System.IO;
3 using System.Net.Sockets;
4
5 int main()
6 {
7 try
8 {
9 TcpSocket socket("www.w3.org", "http");
10 string request = "GET /2001/xml.xsd HTTP/1.1\r\nHost: www.w3.org\r\n\r\n";
11 int numSent = socket.Send(cast<byte*>(cast<void*>(request.Chars())), cast<int>(request.Length()));
12 string reply;
13 IOBuffer buf(4096);
14 int numReceived = socket.Receive(cast<byte*>(buf.Mem()), cast<int>(buf.Size()));
15 while (numReceived > 0)
16 {
17 const char* s = cast<const char*>(buf.Mem());
18 reply.Append(s, numReceived);
19 numReceived = socket.Receive(cast<byte*>(buf.Mem()), cast<int>(buf.Size()));
20 }
21 Console.Out() << reply << endl();
22 }
23 catch (const Exception& ex)
24 {
25 Console.Error() << ex.Message() << endl();
26 return 1;
27 }
28 return 0;
29 }