Thread overview | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 26, 2016 Easy sockets - don't exist yet? | ||||
---|---|---|---|---|
| ||||
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! |
September 27, 2016 Re: Easy sockets - don't exist yet? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vincent | 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. |
September 27, 2016 Re: Easy sockets - don't exist yet? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vincent | 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.
|
September 27, 2016 Re: Easy sockets - don't exist yet? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vincent | 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 |
September 27, 2016 Re: Easy sockets - don't exist yet? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vincent | Just in case, here are the relevant docs: http://dlang.org/phobos/std_net_curl.html |
September 27, 2016 Re: Easy sockets - don't exist yet? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vincent Attachments:
| 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! > > 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! > -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 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 |
September 27, 2016 Re: Easy sockets - don't exist yet? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | 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 :) |
September 27, 2016 Re: Easy sockets - don't exist yet? | ||||
---|---|---|---|---|
| ||||
Posted in reply to JN Attachments:
| 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. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 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 |
September 27, 2016 Re: Easy sockets - don't exist yet? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | 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.
|
October 08, 2016 Re: Easy sockets - don't exist yet? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vincent | 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). |
Copyright © 1999-2021 by the D Language Foundation