CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Which ASCII character to send

    I want to send only one character to the other side to signal that there was an error.

    I'm looking for a character that never appears in a file.

    I looked at the ASCII chart and I thought maybe:

    - 127 177 7F 01111111  Delete
    or
    - 129 201 81 10000001

    http://www.ascii-code.com/

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Which ASCII character to send

    ASCII character 0x81 is the small u umlaut. See http://www.theasciicode.com.ar/
    DEL character (127) can be used by some OS for special purposes. See http://en.wikipedia.org/wiki/ASCII and http://en.wikipedia.org/wiki/Delete_character
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Which ASCII character to send

    Thank you Victor.

    Looks like the DEL character should be OK on Windows.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Which ASCII character to send

    I'm looking for a character that never appears in a file.
    Depends somewhat upon whether a file is type 'text' or 'binary'. In a binary ASCII file any of the characters from 0 to 255 may appear. In a 'text' file 1 - 6, 14 - 26, 28 - 31 and 255 are unlikely to occur.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Which ASCII character to send

    It's for binary too so maybe just one character is not the best solution.

    Thanks Kaud, that's what I wanted to know.
    Last edited by MasterDucky; July 24th, 2014 at 12:11 PM.

  6. #6
    Join Date
    Nov 2003
    Posts
    1,902

    Re: Which ASCII character to send

    You could base64 encode the file contents, then use a NAK (21) (or whatever) in your protocol.

    gg

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Which ASCII character to send

    Quote Originally Posted by MasterDucky View Post
    It's for binary too so maybe just one character is not the best solution.

    Thanks 2Kaud, that's what I wanted to know.
    What are you trying to achieve? If you are using binary files then any sequence of one or more characters could possibly occur in any file.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Which ASCII character to send

    Quote Originally Posted by 2kaud View Post
    What are you trying to achieve? If you are using binary files then any sequence of one or more characters could possibly occur in any file.
    Thats true.

    I would like to signal to the other side that an error occurred and dont wait for the file.

  9. #9
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Which ASCII character to send

    Quote Originally Posted by Codeplug View Post
    You could base64 encode the file contents, then use a NAK (21) (or whatever) in your protocol.
    Base64 doesnt use all the ASCII characters?

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Which ASCII character to send

    Quote Originally Posted by MasterDucky View Post
    I want to send only one character to the other side to signal that there was an error.
    I'm looking for a character that never appears in a file.
    How do you "send" your file?
    Victor Nijegorodov

  11. #11
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Which ASCII character to send

    Quote Originally Posted by VictorN View Post
    How do you "send" your file?
    Windows TCP/IP Send() function.

  12. #12
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Which ASCII character to send

    If all you want to do is to signal an error from the send side, what about just closing the connection? This will be picked up by recv() as an error for which you can test. If you want to resend then the sender can re-open the connection etc.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  13. #13
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Which ASCII character to send

    Quote Originally Posted by Codeplug View Post
    You could base64 encode the file contents, then use a NAK (21) (or whatever) in your protocol.

    gg
    This looks like the best solution.

  14. #14
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Which ASCII character to send

    Also look at the shutdown function in MSDN.

    Besides, this thread is a very good example of how one should NOT ask the question.
    The more reliable question about your problem should have looked like:
    I send a file through a TCP socket.
    If some error occured on the sender side, what should I do or what should I send to the receiver to inform that send operation is broken?
    Then you would have got the valuable answer in some minutes, not in 11 hours!
    Victor Nijegorodov

  15. #15
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Which ASCII character to send

    Yes, but I want to know if it was an error with the connection or with some other operation, like couldn't open a file I asked for or anything else.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured