www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.socket replacement

reply tired_eyes <pastuhov85 gmail.com> writes:
I was a bit surprised to see that std.socket is deprecated as of 
2.069. Just curious, what's wrong with it? And what should I use 
as a replacement? I know there is vibe.socket, but I don't want 
to include fullstack web framework as a dependency just to make 
some HTTP reqests.

I also don't see any proposed replacements in a review queue. 
Will std.socket and std.socketstream be just thrown away?
Nov 29 2015
parent reply tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
On Sunday, 29 November 2015 at 08:56:30 UTC, tired_eyes wrote:
 I was a bit surprised to see that std.socket is deprecated as 
 of 2.069. Just curious, what's wrong with it? And what should I 
 use as a replacement? I know there is vibe.socket, but I don't 
 want to include fullstack web framework as a dependency just to 
 make some HTTP reqests.

 I also don't see any proposed replacements in a review queue. 
 Will std.socket and std.socketstream be just thrown away?
I would say "WTF" at first, then checked the documentation, but don't see anything about deprecation. My current whole business relies on that.
Nov 29 2015
parent reply tired_eyes <pastuhov85 gmail.com> writes:
On Sunday, 29 November 2015 at 09:05:37 UTC, tcak wrote:
 On Sunday, 29 November 2015 at 08:56:30 UTC, tired_eyes wrote:
 I was a bit surprised to see that std.socket is deprecated as 
 of 2.069. Just curious, what's wrong with it? And what should 
 I use as a replacement? I know there is vibe.socket, but I 
 don't want to include fullstack web framework as a dependency 
 just to make some HTTP reqests.

 I also don't see any proposed replacements in a review queue. 
 Will std.socket and std.socketstream be just thrown away?
I would say "WTF" at first, then checked the documentation, but don't see anything about deprecation. My current whole business relies on that.
Wow, sorry, I meant std.stream and std.socketstream, not std.socket and std.socketstream
Nov 29 2015
parent reply Alex Parrill <initrd.gz gmail.com> writes:
On Sunday, 29 November 2015 at 09:12:14 UTC, tired_eyes wrote:
 On Sunday, 29 November 2015 at 09:05:37 UTC, tcak wrote:
 On Sunday, 29 November 2015 at 08:56:30 UTC, tired_eyes wrote:
 I was a bit surprised to see that std.socket is deprecated as 
 of 2.069. Just curious, what's wrong with it? And what should 
 I use as a replacement? I know there is vibe.socket, but I 
 don't want to include fullstack web framework as a dependency 
 just to make some HTTP reqests.

 I also don't see any proposed replacements in a review queue. 
 Will std.socket and std.socketstream be just thrown away?
I would say "WTF" at first, then checked the documentation, but don't see anything about deprecation. My current whole business relies on that.
Wow, sorry, I meant std.stream and std.socketstream, not std.socket and std.socketstream
std.stream, and the stream interface in general, is deprecated in favor of ranges, which are more generic and flexible.
Nov 29 2015
parent reply tired_eyes <pastuhov85 gmail.com> writes:
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.
Nov 29 2015
parent Max Freck <maxim freck.pp.ru> writes:
On Sunday, 29 November 2015 at 18:00:34 UTC, tired_eyes wrote:
 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.
In case someone is still looking for the answer, just like me. It will be something like that: import std.stdio; import std.socket; enum receiveBufferLength = 1024; void main() { auto socket = new TcpSocket(new InternetAddress("dlang.org", 80)); scope(exit) socket.close(); socket.send("GET http://dlang.org HTTP/1.1\r\nHost: dlang.org\r\nConnection: close\r\n\r\n"); string response; char[receiveBufferLength] receiveBuffer; while (true) { auto received = socket.receive(receiveBuffer[0 .. receiveBufferLength]); response ~= receiveBuffer[0 .. received]; if (received == 0) break; } write(response); }
Sep 03 2016