Search code examples
operating-systemterminaltelneteol

Does \n\r behave differently on different OS?


I have a server and a client program that talks to eachother over a socket connection. It sends strings of data that I monitor via telnet / (or terminal? on mac).

It works fine, when I use my MAC as a server and my PC as a client. It does not work when I use my MAC as a client, and PC as a server... (!?)

Could it be that it the interperets "\n\r" (EOL?) differently since there are two different OS?

Does anybody have a clue / tip / workaround on how to solve this easy?


Solution

  • Windows actually uses \r\n as EOL. It shouldn't behave differently on different OSes, though. Mac uses \r, so it ignores \n, and vice versa for *nix. Windows ignores both \r and \n unless they're next to each other in the order \r\n.

    When programming with EOL, most languages only use \n and auto-convert the format when necessary.