Ascii on TCP socket

后端 未结 3 1486
孤独总比滥情好
孤独总比滥情好 2021-01-14 08:39

Anyone could pass me an example of sending Ascii msg over TCP?(couldnt find example on the net)

thanks,

ray.

3条回答
  •  逝去的感伤
    2021-01-14 09:11

    Not stated in the original question is whether ASCII control codes have to handled.

    While the accepted answer works for printable ASCII characters I've had problems (on Windows 7 Enterprise SP1) using it for strings containing ASCII control codes, especially strings containing any of the java newline "characters", e.g. VT, CR, LF, etc. A workaround is to send the string as bytes and convert it back to a string at the far end.

    See my answer to this question for how to handle that situation.

    Reading Lines and byte[] from input stream

    and my closely related question and it's accepted answer:

    Need TCPIP client that blocks until a specific character sequence is received

提交回复
热议问题