std.socket replacement

tired_eyes via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 29 10:00:32 PST 2015


On Sunday, 29 November 2015 at 16:10:22 UTC, Alex Parrill wrote:
> std.stream, and the stream interface in general, is deprecated 
> in favor of ranges, which are more generic and flexible.

Could you please give a small example?
Consider this minimal app:


import std.stdio;
import std.socket;
import std.socketstream;

void main() {
     auto socket = new TcpSocket(new InternetAddress("dlang.org", 
80));
     scope(exit) socket.close();

     auto ss = new SocketStream(socket);
     ss.writeString("GET http://dlang.org HTTP/1.1\r\n"
                    "Host: dlang.org\r\n"
                    "Connection: close\r\n"
                    "\r\n");

     while (! ss.eof) {
         writeln(ss.readLine());
     }
}


How should it look with ranges instead of socketstream? I thought 
I understand ranges in general, but I can't figure out how they 
can be applied to this case.


More information about the Digitalmars-d-learn mailing list