Easy sockets - don't exist yet?

Satoshi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Sep 26 23:43:28 PDT 2016


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.


More information about the Digitalmars-d-learn mailing list