Receiving data into a type using sockets
Jonathan Sternberg
jonathansternberg at gmail.com
Sun Jun 5 12:49:18 PDT 2011
Cool. It compiles, but it doesn't seem to be doing exactly what I want. Say I send
2 integers from the server to the client. When I do this on the client, it seems
to do the wrong thing.
int first, second;
auto sock = new TcpSocket();
sock.connect(new InternetAddress("localhost", 10000));
writeln( sock.receive((&first)[0..int.sizeof]) );
writeln( sock.receive((&second)[0..int.sizeof] );
This seems to print 8 and then block on the second call to receive. I thought that
D was supposed to recognize that the array was only 4 bytes long and read only
that much. (note: on a 32-bit machine, so int comes out to 4 bytes)
When I do:
writeln( (&first)[0..int.sizeof].length );
It prints 4 as it's supposed to.
More information about the Digitalmars-d-learn
mailing list