www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Easy sockets - don't exist yet?

reply Vincent <thornik gmail.com> writes:
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!
Sep 26 2016
next sibling parent haxx <skocznymr gmail.com> writes:
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.
Sep 26 2016
prev sibling next sibling parent Satoshi <satoshi gshost.eu> writes:
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!
-idiotic "buffers of bytes"! It's not buffer of bytes who is idiotic... communication over sockets are binary, not in text form. Sending structs in binary form is much better idea than send it in text form. e.g. struct Message { int magic; int command; int dataLength; // length of data pushed after this struct } then you can receive sizeof(Message), check magic, receive dataLength of bytes and call delegate by the command int in Message... UNIX sockets are not stupid, only you cannot use it.
Sep 26 2016
prev sibling next sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Am Mon, 26 Sep 2016 23:40:10 +0000
schrieb Vincent <thornik gmail.com>:

 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
Haha, this is not how I learned network layers at school. You seem to want on the ... Network Layer (3): A connection based socket using the Internet Protocol Transport Layer (4): A stateful connection using TCP Application Layer (6): HTTP Just that you don't ask for HTTP directly, but shoehorn a packet based socket into sending microscopic strings. In this case I recommend cURL, which you can feed with all the header data at once and sends your complete request in one packet. That'll also handle most of the HTTP specialties. Not all data transmissions via IP are TCP either. A good bunch is sent via stateless UDP. That would not be considered a stream though. I'm just getting at the name "ClientSocket" here, which can entail more than TCP/IP streams. -- Marco
Sep 27 2016
prev sibling next sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Just in case, here are the relevant docs:
http://dlang.org/phobos/std_net_curl.html
Sep 27 2016
prev sibling next sibling parent reply Russel Winder via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
Why not just create a binding to 0MQ and get much, much more than asked
for?

On Mon, 2016-09-26 at 23:40 +0000, Vincent via Digitalmars-d-learn
wrote:
 Hello, guys!
=20
 I was very surprised that module 'socketstream' was deprecated.=C2=A0
 Usually if something become obsolete, there is some perfect=C2=A0
 replacement! But my digging in Inet and forums gave nothing, but=C2=A0
 "outdated" examples with 'SocketStream' class. So first question=C2=A0
 is WHAT Phobos has to replace SocketStream?
 To avoid unnecessary mail bouncing, I write upfront what I expect=C2=A0
 from normal Socket implementation (kind of interface) :
=20
 1. Easy to use. No more stupid "UNIX sockets", "TCP types" and so=C2=A0
 on. Just simple as this:
=20
 // Client side
 auto sock =3D new ClientSocket("google.com", 80);
 sock.WriteLine("GET / HTTP/1.0");
 sock.WriteLine("Host: google.com");
 sock.WriteLine();// empty line sent
=20
 // Server side:
 auto svc =3D new ServerSocket("Bound.To.This.IP", 1000);
 while ((auto ClientSock =3D svc.AcceptClient()) !is null) {
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0auto command =3D ClientSock.ReadLine();// t=
his is important -=C2=A0
 read by line, not idiotic "buffers of bytes"!
 	ClientSock.WriteLine(command ~ ` yourself!`);
 	ClientSock.Close();
 }
=20
 2. Of course integration with std.stream could be nice, it gives=C2=A0
 "for free" readLine and other methods.
 3. Ability to 'get and forget': hardly all of us wanna deal with=C2=A0
 "get portion, write portion to disk, blah". Simple=C2=A0
 "sock.ReceiveFile(`http://porno/girl.avi`,=C2=A0
 `c:\diploma_work.avi`)" could be enough.
 =C2=A0=C2=A0=C2=A0=C2=A0Some kind of "progress report" callback would be =
nice.
 4. SSL/TLS out-of-the-box. In example above it should be same=C2=A0
 easy as:
=20
 auto sock =3D new ClientSocket("google.com", 80, Proto.TLS);
=20
=20
 At the moment it's all I need, but hope you'll be happy too with=C2=A0
 such interface. Sockets are SOOO important, that I cannot believe=C2=A0
 we don't have so easy API now. Or if we have, please share!
=20
 Thanks everybody!
=20
--=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Sep 27 2016
parent reply JN <666total wp.pl> writes:
On Tuesday, 27 September 2016 at 09:23:35 UTC, Russel Winder 
wrote:
 Why not just create a binding to 0MQ and get much, much more 
 than asked for?
http://code.dlang.org/packages/zmqd http://code.dlang.org/packages/zeromq http://code.dlang.org/packages/dzmq or use existing ones :)
Sep 27 2016
parent reply Russel Winder via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Tue, 2016-09-27 at 10:16 +0000, JN via Digitalmars-d-learn wrote:
 On Tuesday, 27 September 2016 at 09:23:35 UTC, Russel Winder=C2=A0
 wrote:
=20
 Why not just create a binding to 0MQ and get much, much more=C2=A0
 than asked for?
=20
=20 http://code.dlang.org/packages/zmqd http://code.dlang.org/packages/zeromq http://code.dlang.org/packages/dzmq =20 or use existing ones :)
Even better, except it would be good if there was one. Maybe the authors of these three can get together and make a single binding to avoid dispersion. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Sep 27 2016
parent JN <666total wp.pl> writes:
On Tuesday, 27 September 2016 at 11:16:00 UTC, Russel Winder 
wrote:
 On Tue, 2016-09-27 at 10:16 +0000, JN via Digitalmars-d-learn 
 wrote:
 On Tuesday, 27 September 2016 at 09:23:35 UTC, Russel Winder 
 wrote:
 
 Why not just create a binding to 0MQ and get much, much more 
 than asked for?
 
http://code.dlang.org/packages/zmqd http://code.dlang.org/packages/zeromq http://code.dlang.org/packages/dzmq or use existing ones :)
Even better, except it would be good if there was one. Maybe the authors of these three can get together and make a single binding to avoid dispersion.
Not really, because some of these are just pure C bindings, while some offer D wrappers for the ZeroMQ interface. Both are good to have, depending on the needs.
Sep 27 2016
prev sibling next sibling parent reply Karabuta <karabutaworld gmail.com> writes:
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) :

 [...]
This is how a usable socket in a standard library should be http://dsfml.com/docs/sockets.html. This is using DSFML (a D bindings to SFML).
Oct 08 2016
parent reply Bauss <jj_1337 live.dk> writes:
Wrote some pretty simple sockets that you could use (Based on 
vibe.d though.)

https://github.com/bausshf/cheetah
Oct 10 2016
parent Konstantin Kutsevalov <adamasantares gmail.com> writes:
On Monday, 10 October 2016 at 07:37:48 UTC, Bauss wrote:
 Wrote some pretty simple sockets that you could use (Based on 
 vibe.d though.)

 https://github.com/bausshf/cheetah
Hi, Yes I saw it, but not sure. Does it make sense to use vibe.d only for sockets. I mean, it like a web framework with many dependencies etc...
Oct 10 2016
prev sibling parent reply Konstantin Kutsevalov <adamasantares gmail.com> writes:
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?
Hello, I'm agree with your main question. This looks very good http://dsfml.com/docs/sockets.html, but, there is no any answer for the question. Why 'socketstream' was deprecated when no any replacement modules? It looks strange, like you are removing feature from your app because his code old and don't write new code for same feature, and just say to users: no feature anymore, haha. So anyone know the answer?
Oct 09 2016
next sibling parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Monday, October 10, 2016 01:43:54 Konstantin Kutsevalov via Digitalmars-d-
learn wrote:
 Why 'socketstream' was
 deprecated when no any replacement modules? It looks strange,
 like you are removing feature from your app because his code old
 and don't write new code for same feature, and just say to users:
 no feature anymore, haha.

 So anyone know the answer?
Quite some time ago, it was decided that the *stream modules as they were were unacceptable and that they needed to be replaced with something range-based (they come from early D1 and have never really been updated since), and they were marked in their documentation to indicate that they were going to be removed in the future. But apparently, no one cared enough about that functionality to actually design a replacement, and it sat there for years. So, it was finally decided that rather than just having code that was not up to our current standards sit there with a warning on it, it should be removed. So, they those modules were deprecated (and will be fully removed in the next release). I'm sure that part of what it comes down to is that ranges in generally largely slove the problem that a stream tries to solve (though std.socket unfortunately doesn't provide an easy way to get a range over a socket), making the *stream modules largely redundant, and the read, write, and peek functions in std.bitmanip do a lot of the rest of what would need to be done with a stream that isn't natively part of a range. So, enough of the functionality is there in a more general form that a replacement isn't necessarily needed (even if it might be nice), and if anyone cared enough to do it, they haven't tried to get it into Phobos (or even put it up on code.dlang.org AFAIK). Clearly, some folks use the *stream stuff, but it doesn't seem like many do, and it's also clear that - for whatever reason - no one has cared enough to come up with a replacement for Phobos. So, it's simply gone. But if someone wants to propose a replacement, they're certainly still free to do so. - Jonathan M Davis
Oct 09 2016
parent Konstantin Kutsevalov <adamasantares gmail.com> writes:
On Monday, 10 October 2016 at 02:54:09 UTC, Jonathan M Davis 
wrote:
 On Monday, October 10, 2016 01:43:54 Konstantin Kutsevalov via 
 So, it's simply gone. But if someone wants to propose a 
 replacement, they're certainly still free to do so.

 - Jonathan M Davis
I see, thank you for answer
Oct 10 2016
prev sibling parent Daniel Kozak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
Dne 10.10.2016 v 03:43 Konstantin Kutsevalov via Digitalmars-d-learn 
napsal(a):

 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?
Hello, I'm agree with your main question. This looks very good http://dsfml.com/docs/sockets.html, but, there is no any answer for the question. Why 'socketstream' was deprecated when no any replacement modules? It looks strange, like you are removing feature from your app because his code old and don't write new code for same feature, and just say to users: no feature anymore, haha. So anyone know the answer?
Until some replacment will occure in phobos socketstream is and will be available through https://code.dlang.org/packages/undead
Oct 09 2016