Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Problem Transmitting Data via TCP/IP

by scorpio17 (Canon)
on Aug 09, 2012 at 18:08 UTC ( [id://986570]=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. 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));
    
  2. or download this
    Socket().Write( Request.begin(), Request.length() );
    
  3. 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
    
  4. or download this
    char msg2[256];
    memset(msg2,0,256);
    ...
    Socket().Read(msg2, nlen); // read the request
    log.Printf("Request: %s", msg2);
    
  5. or download this
    New client connection accepted
    1. msg2: 0000 0000 0000 0011
    ...
    Request: abcdefghijklmnopq
    Response: hello world
    Closing connection.
    
  6. 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)
    
  7. or download this
    #!/usr/bin/perl
    use strict;
    ...
      return $output;
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://986570]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-19 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found