RosettaCodeData/Task/Hello-world-Web-server/D/hello-world-web-server.d

25 lines
469 B
D
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
import std.socket, std.array;
ushort port = 8080;
void main() {
2014-01-17 05:32:22 +00:00
Socket listener = new TcpSocket;
listener.bind(new InternetAddress(port));
listener.listen(10);
2013-04-10 21:29:02 -07:00
2014-01-17 05:32:22 +00:00
Socket currSock;
2013-04-10 21:29:02 -07:00
2014-01-17 05:32:22 +00:00
while(cast(bool)(currSock = listener.accept())) {
currSock.sendTo(replace(q"EOF
2013-04-10 21:29:02 -07:00
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
<html>
2014-01-17 05:32:22 +00:00
<head><title>Hello, world!</title></head>
<body>Hello, world!</body>
2013-04-10 21:29:02 -07:00
</html>
EOF", "\n", "\r\n"));
2014-01-17 05:32:22 +00:00
currSock.close();
}
2013-04-10 21:29:02 -07:00
}