digitalmars.D.learn - About void[] and asockets
- Jolly James (9/9) Feb 22 2017 For sure, some might know ae. I am trying to use it as TcpServer.
- Adam D. Ruppe (11/15) Feb 22 2017 They represent an array of anything; the user can pass ubyte[] to
- Jolly James (4/20) Feb 22 2017 Thank you very much!
- Jolly James (6/31) Feb 22 2017 But I have one problem: How to use the constructor of the Data
- Adam D. Ruppe (3/6) Feb 22 2017 I don't know the library, so I'd have to see the Data class, but
- Jolly James (7/15) Feb 22 2017 Silly me!
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 2017
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 2017
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:Thank you very much! Now it makes sense and I understand.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 2017
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: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)On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James wrote:Thank you very much! Now it makes sense and I understand.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 2017
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 2017
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: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`, ...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 2017