tiny web server in D
Dr.Smith
ds at nomail.com
Wed Jul 13 20:48:14 PDT 2011
While the following D program runs without compiler error, it seems unable to serve a web page. Is there a better way?
import std.socket, std.string;
void main() {
Socket listener = new TcpSocket;
assert(listener.isAlive);
listener.bind(new InternetAddress(8080));
listener.listen(10);
string webpage = "index.html";
Socket currSock;
uint bytesRead;
ubyte buff[1];
while(1) {
currSock = listener.accept();
while ((bytesRead = currSock.receive(buff)) > 0) {
currSock.sendTo(webpage);
}
currSock.close();
buff.clear();
}
}
More information about the Digitalmars-d-learn
mailing list