Writing to a socket with hex and string characters

This is a discussion on Writing to a socket with hex and string characters within the C++ Programming forums, part of the General Programming Boards category; Hi I have a line of text which i have read in from a file which I wish to output ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    1

    Writing to a socket with hex and string characters

    Hi

    I have a line of text which i have read in from a file which I wish to output to a socket. The problem that i have is that i need to append SOH to the front of the text and add CR and LF to the end of the text then send to the socket.

    i have defined
    Code:
    const int SOH 0x01
    const int CR 0x12
    const int LF 0x15
    ifstream file
    string line
    Is "const int" the right thing to use?

    I do a
    Code:
    getline(file,line)
    How do i now put the message together and do a
    sendto(filedescriptor, string, length....etc)


    Thanks
    Tara

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Why not
    Code:
    const string SOH("\x01");
    const string CR("\x12");
    const string LF("\x15");
    string result;
    result = SOH + line + CR + LF;
    ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 06-16-2011, 12:59 PM
  2. Hex String to Decimal converter
    By wrex in forum C Programming
    Replies: 16
    Last Post: 11-05-2008, 06:06 PM
  3. Converting a binary string to hex
    By maxhavoc in forum C++ Programming
    Replies: 6
    Last Post: 07-25-2006, 01:46 PM
  4. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  5. Writing 64 bit value in hex to a string
    By rahulgbe in forum C Programming
    Replies: 2
    Last Post: 03-18-2006, 01:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21