Creating a C# like Asynchronous Socket

DrCataclysm 4002600 at ba-glauchau.de
Mon Nov 6 09:04:37 UTC 2017


On Monday, 6 November 2017 at 08:03:23 UTC, DrCataclysm wrote:
> On Sunday, 5 November 2017 at 14:47:37 UTC, DrCataclysm wrote:
>> I am trying to build something like the asynchronous Sockets 
>> from C# .NET but I'm stuck at the accepting phase.
>> 
>> ....
>>
>> The client created by _socket.accept() cannot receive any data.
>>
>> client.receive() immediately returns 0 like a non-blocking 
>> socket. I think it has something to do with the original 
>> socket being owned by a different thread.
>>
>> I am not very familiar with multitasking/multithreading in D 
>> so any help would be appreciated.
>

Found my error in the following lines:

>             _connection = _socket.accept();
>             assert(_connection !is null); // this works
>             ubyte[] buffer;
>             // as blocking
>             auto receive = _connection.receive(buffer);

I forgot to give bugger a size. If not given, the compiler 
declares
buffer.size as 0.

receive writes data from the socket into the buffer and returns 
the length of the data. If the buffer is too small it only 
receives as much data as fits in the buffer. If the buffer is too 
small for any data it just returns with 0;




More information about the Digitalmars-d-learn mailing list