TCP Socket Client Example
Laeeth Isharc via Digitalmars-d
digitalmars-d at puremagic.com
Sat Aug 15 15:01:03 PDT 2015
On Friday, 14 August 2015 at 14:06:03 UTC, Kingsley wrote:
> Hi
>
> Does anyone have some examples of making a client socket
> connection to a host on a port and parsing the incoming data in
> some kind of loop.
>
> --K
Nanomsg might be one option if you control the host - by one of
the main authors of Zeromq. He decided to rewrite in C and it
addresses some architectural flaws of Zeromq. (At least one
smart guy in London D community agrees it's better).
http://www.infoq.com/news/2012/03/Crossroads-IO
http://nanomsg.org/
Nanomsg itself is at an early stage, and I think the author has a
lot on his plate (if I recall right he is now at Google) so
progress isn't as fast as one would like.
But it's usable, and I have some primitive D bindings/wrapper
here. Nanomsg seems stable enough for me, and one or two
glitches in bindings/wrappers but I am using them for my stuff.
I know that if nanomsg ends up being a disaster I can always
switch to zeromq, which is similar enough to do so easily.
https://github.com/Laeeth/d-nanomsg.git
D written for C style bindings for pipeline here:
int node0 (string xurl)
{
int sock = nn_socket (AF_SP, NN_PULL);
auto url=xurl.toStringz;
assert(sock >= 0);
assert(nn_bind (sock, url) >= 0);
while (1)
{
char* buf = cast(char*)0;
int bytes = nn_recv (sock, &buf, NN_MSG, 0);
assert (bytes >= 0);
writefln("NODE0: RECEIVED %s bytes: \"%s\"",
bytes,to!string(buf));
nn_freemsg (buf);
}
return 0;
}
More information about the Digitalmars-d
mailing list