- or download this
std::string Request("abcdefghijklmnopq"); // just an example, for test
+ing
uint32_t msgLen = Request.length(); // msgLen = 17 for this test
+ case
msgLen = htonl(msgLen); // convert to network ordered long int
Socket().Write( reinterpret_cast< char * >(&msgLen), sizeof(msgLen));
- or download this
Socket().Write( Request.begin(), Request.length() );
- or download this
Socket().Read(&msgLen, sizeof(msgLen));
msgLen = ntohl(msgLen); // convert back from network ordered long int
Socket().Read(&buffer, msgLen); // read response into buffer
- or download this
char msg2[256];
memset(msg2,0,256);
...
Socket().Read(msg2, nlen); // read the request
log.Printf("Request: %s", msg2);
- or download this
New client connection accepted
1. msg2: 0000 0000 0000 0011
...
Request: abcdefghijklmnopq
Response: hello world
Closing connection.
- or download this
New client connection accepted
msg2: 0032 0038 0035 0032
...
msg2: 50 56 53 50
before ntohl: nlen = 842348594 (hex: 32353832)
after ntohl: nlen = 842544434 (hex: 32383532)
- or download this
#!/usr/bin/perl
use strict;
...
return $output;
}