On Sunday, 24 May 2020 at 08:10:33 UTC, Russel Winder wrote:
Hi,

Clearly Vibe.d is mostly for people doing HTTP and HTTPS stuff. Yet it claims to be able to support TCP and UDP working with other protocols. However, all the serious examples are HTTP/HTTPS related. All the TCP and UDP examples are basically trivial and thus useless to me for learning.

I am hoping I have just missed the page/example that does something more than just echo for a TCP server. If I haven't, is ther an example somewhere people know of that I can look at?

My problem is that I am not sure how to do a read/write system that is not
just echo using the "connection.write(connection)" trick.

Here is a quick example that I took from some old code I had:

I cannot guarantee that it works as it was written for an older version of vibe about 3 years ago.

I have not structured it either and just put all snippets together here.

listeners = [listenTCP(port, &handleConnections, ip)];

or

listeners = listenTCP(port, &handleConnections);

void handleConnections(TCPConnection connection) {
   ...
}

auto buf = new ubyte[amount];

connection.read(temp);

connection.write(buf);

Then of course you need to handle all that in the way your server/client operates.

How you implement it is of course just in similar fashion to general socket servers.

You read N bytes until you have received all bytes for the specific packet.

Then you can write your packets back afterwards.

Someone can correct me if I am wrong but I believe you can yield from the handlers in vibe.d

So if you haven't received all data yet you can yield between each call to read until all bytes have been received.

I will admit I have not used sockets in vibe.d for a very long time though.

Reply via email to