www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - About void[] and asockets

reply Jolly James <j.j jmail.com> writes:
For sure, some might know ae. I am trying to use it as TcpServer. 
I got almost everything working fine concerning connection 
establishment and disconnecting. But there is one thing that 
makes it hard for me to understand, how to handle data.

https://github.com/CyberShadow/ae/blob/master/net/asockets.d

Well, what are these void-arrays for real? I mean, they contain 
data what does not make them really void, does it?

And how to I get received data out of Data.content[]?
How to use TcpConnection.send()? E.g. for sending a string?
Feb 22
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James wrote:
 Well, what are these void-arrays for real? I mean, they contain 
 data what does not make them really void, does it?
They represent an array of anything; the user can pass ubyte[] to it, or int[] to it, or char[] to it, or anything else (even string if it is in void[] or const void[]).
 And how to I get received data out of Data.content[]?
 How to use TcpConnection.send()? E.g. for sending a string?
Cast it to `const(ubyte)[]` then use it as a bag of bytes. That's almost always what you want to do inside. The function signature uses `in void[]` instead of `ubyte[]` because void will accept strings and other stuff too, whereas ubyte specifically requires it to be typed as bye. You want to use it INTERNALLY as bytes, but the external interface can accept almost anything.
Feb 22
parent reply Jolly James <j.j jmail.com> writes:
On Wednesday, 22 February 2017 at 17:01:11 UTC, Adam D. Ruppe 
wrote:
 On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James 
 wrote:
 Well, what are these void-arrays for real? I mean, they 
 contain data what does not make them really void, does it?
They represent an array of anything; the user can pass ubyte[] to it, or int[] to it, or char[] to it, or anything else (even string if it is in void[] or const void[]).
 And how to I get received data out of Data.content[]?
 How to use TcpConnection.send()? E.g. for sending a string?
Cast it to `const(ubyte)[]` then use it as a bag of bytes. That's almost always what you want to do inside. The function signature uses `in void[]` instead of `ubyte[]` because void will accept strings and other stuff too, whereas ubyte specifically requires it to be typed as bye. You want to use it INTERNALLY as bytes, but the external interface can accept almost anything.
Thank you very much! Now it makes sense and I understand.
Feb 22
parent reply Jolly James <j.j jmail.com> writes:
On Wednesday, 22 February 2017 at 17:06:51 UTC, Jolly James wrote:
 On Wednesday, 22 February 2017 at 17:01:11 UTC, Adam D. Ruppe 
 wrote:
 On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James 
 wrote:
 Well, what are these void-arrays for real? I mean, they 
 contain data what does not make them really void, does it?
They represent an array of anything; the user can pass ubyte[] to it, or int[] to it, or char[] to it, or anything else (even string if it is in void[] or const void[]).
 And how to I get received data out of Data.content[]?
 How to use TcpConnection.send()? E.g. for sending a string?
Cast it to `const(ubyte)[]` then use it as a bag of bytes. That's almost always what you want to do inside. The function signature uses `in void[]` instead of `ubyte[]` because void will accept strings and other stuff too, whereas ubyte specifically requires it to be typed as bye. You want to use it INTERNALLY as bytes, but the external interface can accept almost anything.
Thank you very much! Now it makes sense and I understand.
But I have one problem: How to use the constructor of the Data class? No matter how I try, I am always getting: Error: none of the overloads of '__ctor' are callable using argument types (Data*), candidates are: (my-project)
Feb 22
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 22 February 2017 at 17:53:21 UTC, Jolly James wrote:
 No matter how I try, I am always getting:
 Error: none of the overloads of '__ctor' are callable using 
 argument types (Data*), candidates are: (my-project)
I don't know the library, so I'd have to see the Data class, but you might just be using &data when you should be using plain data.
Feb 22
parent Jolly James <j.j jmail.com> writes:
On Wednesday, 22 February 2017 at 17:57:31 UTC, Adam D. Ruppe 
wrote:
 On Wednesday, 22 February 2017 at 17:53:21 UTC, Jolly James 
 wrote:
 No matter how I try, I am always getting:
 Error: none of the overloads of '__ctor' are callable using 
 argument types (Data*), candidates are: (my-project)
I don't know the library, so I'd have to see the Data class, but you might just be using &data when you should be using plain data.
Silly me! Now I used Xamarin's Find-Usage-Feature, found one usage in ae and realized that there is no reason for using the keyword `new`, as Data is a struct (and so one does not need `new` unlike in C#) ...
Feb 22