Skip to content

Code Examples

rgsilva edited this page Jan 1, 2012 · 1 revision

TcpSocket

This TcpSocket example simulates a HTTP 1.1 request against a valid IP address on the Internet, showing the HTML source of the page.

import std.io;
import std.net;

Int i = 8;
String page;

TcpSocket s = TcpSocket();
s.setHost("200.132.43.5");
s.setPort(80);
s.connect();

s.send("GET / HTTP/1.1\n");
s.send("Host: 200.132.43.5\n");
s.send("\n");

while (i > 0) {
    page = s.receive();
    print(page);

    if (!s.poll()) {
        i--;
    }
}
println("-- Finished. --");
Clone this wiki locally