On Monday, 26 September 2016 at 23:40:10 UTC, Vincent wrote:
Hello, guys!
I was very surprised that module 'socketstream' was deprecated.
Usually if something become obsolete, there is some perfect
replacement! But my digging in Inet and forums gave nothing,
but "outdated" examples with 'SocketStream' class. So first
question is WHAT Phobos has to replace SocketStream?
To avoid unnecessary mail bouncing, I write upfront what I
expect from normal Socket implementation (kind of interface) :
1. Easy to use. No more stupid "UNIX sockets", "TCP types" and
so on. Just simple as this:
// Client side
auto sock = new ClientSocket("google.com", 80);
sock.WriteLine("GET / HTTP/1.0");
sock.WriteLine("Host: google.com");
sock.WriteLine();// empty line sent
// Server side:
auto svc = new ServerSocket("Bound.To.This.IP", 1000);
while ((auto ClientSock = svc.AcceptClient()) !is null) {
auto command = ClientSock.ReadLine();// this is important -
read by line, not idiotic "buffers of bytes"!
ClientSock.WriteLine(command ~ ` yourself!`);
ClientSock.Close();
}
2. Of course integration with std.stream could be nice, it
gives "for free" readLine and other methods.
3. Ability to 'get and forget': hardly all of us wanna deal
with "get portion, write portion to disk, blah". Simple
"sock.ReceiveFile(`http://porno/girl.avi`,
`c:\diploma_work.avi`)" could be enough.
Some kind of "progress report" callback would be nice.
4. SSL/TLS out-of-the-box. In example above it should be same
easy as:
auto sock = new ClientSocket("google.com", 80, Proto.TLS);
At the moment it's all I need, but hope you'll be happy too
with such interface. Sockets are SOOO important, that I cannot
believe we don't have so easy API now. Or if we have, please
share!
Thanks everybody!
Sockets in D are a thin layer over the BSD sockets, and they do
well in that aspect. What you are asking for aren't sockets, but
more like a HTTP client, have you checked
https://dlang.org/phobos/etc_c_curl.html ? It should be able to
do the functionality you are looking for. If not, there are some
packages on http://code.dlang.org/, such as
http://code.dlang.org/packages/requests or
http://code.dlang.org/packages/libhttp2 , which seem like a good
fit as well.