Re: Using Vibe.d for not HTTP

2020-05-25 Thread Russel Winder via Digitalmars-d-learn
On Mon, 2020-05-25 at 12:29 +, Panke via Digitalmars-d-learn wrote:
> 
[…]
> https://vibed.org/api/vibe.core.core/runTask ?
> 

Possibly, it is just that the documentation is sadly lacking in examples of
use.

-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk



signature.asc
Description: This is a digitally signed message part


Re: Using Vibe.d for not HTTP

2020-05-25 Thread Panke via Digitalmars-d-learn

On Monday, 25 May 2020 at 12:04:12 UTC, Russel Winder wrote:


Now I need to find out how to spawn a task that can send out 
data even when the connection handler is blocked awaiting 
something to read.



https://vibed.org/api/vibe.core.core/runTask ?




Re: Using Vibe.d for not HTTP

2020-05-25 Thread Russel Winder via Digitalmars-d-learn
On Mon, 2020-05-25 at 11:55 +0200, Daniel Kozak via Digitalmars-d-learn wrote:
[…]
> 
> https://run.dlang.io/is/SMLuA2

Thanks for this pointer. It was very helpful to read it as it confirmed that I
was going doing the right thing in my code. That you have two sources adding
some interleaving is most interesting and very informative, useful to read.

Now I need to find out how to spawn a task that can send out data even when
the connection handler is blocked awaiting something to read.

I also need to find out why I am now getting a SIGSEGV I wasn't getting before
when no changes seem to have occured in the code. lldb is not really that
useful, just as gdb wasn't. :-(

-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk



signature.asc
Description: This is a digitally signed message part


Re: Using Vibe.d for not HTTP

2020-05-25 Thread Daniel Kozak via Digitalmars-d-learn
On Sun, May 24, 2020 at 10:10 AM Russel Winder via Digitalmars-d-learn
 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?


https://run.dlang.io/is/SMLuA2


Re: Using Vibe.d for not HTTP

2020-05-24 Thread Panke via Digitalmars-d-learn

On Sunday, 24 May 2020 at 16:14:58 UTC, Russel Winder wrote:

On Sun, 2020-05-24 at 17:01 +0100, Russel Winder wrote:



[…]

connection.read(buffer, IOMode.once);

What an idiot I am, this call returns the read count, which 
makes it fine.


Progress now being made.


I had a look. Documentation could be better. I think the other 
call does not return it, because it always reads until the buffer 
is filled.


Re: Using Vibe.d for not HTTP

2020-05-24 Thread Russel Winder via Digitalmars-d-learn
On Sun, 2020-05-24 at 17:01 +0100, Russel Winder wrote:
> 
[…]
> connection.read(buffer, IOMode.once);
> 
What an idiot I am, this call returns the read count, which makes it fine.

Progress now being made.

-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk



signature.asc
Description: This is a digitally signed message part


Re: Using Vibe.d for not HTTP

2020-05-24 Thread Russel Winder via Digitalmars-d-learn
On Sun, 2020-05-24 at 12:26 +, bauss via Digitalmars-d-learn wrote:
[…]

Thanks for responding, much appreciated.

> void handleConnections(TCPConnection connection) {
> ...
> }

I guess I was looking for an example of what to put in this function!

> auto buf = new ubyte[amount];
> 
> connection.read(temp);

The documentation on read is sadly lacking :-(
https://vibed.org/api/vibe.core.net/TCPConnection.read

It seems to block pending filling all the spaces in the buffer. Not really
very useful.

I tried:

connection.read(buffer, IOMode.once);

but there seems no report on how many bytes were read, you have to guess by
parsing the buffer and making assumptions. Unless I am missing something,
which I really hope I am.


> connection.write(buf);

Not quite at that stage yet!

[…]

-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk



signature.asc
Description: This is a digitally signed message part


Re: Using Vibe.d for not HTTP

2020-05-24 Thread bauss via Digitalmars-d-learn

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, , ip)];

or

listeners = listenTCP(port, );

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.