Socket libraries question.

Per Hedeland per@REDACTED
Wed May 26 15:49:27 CEST 1999

Mickael Remond wrote:
>I am trying to create a socket application working both on Linux and
>I found that the way of receving packet is not the same under Linux or
>under Windows. I am using the {packet, 0} option.
>Under Linux, the program seems to be waiting for a carriage return before
>receiving. Under Windows, the program is receiving and answer after each
>key pressed.
>What am I missing ?

Well, what *I* am missing is a description of how the characters get
from your keyboard to the socket.:-) Sockets don't generally care about
carriage returns and such things, ttys do.

>Is there a standard socket comportement for receiving the packets only on
>carriage return (for example, each time the enter key is pressed under

OK, I assume that you've written a TCP server in Erlang, that is
accepting connections on some port, and then connect to it using the
standard 'telnet' client of the respective OS - in that case, the
difference you're seeing is entirely due to the different behaviour of
the respective telnet clients.

The telnet protocol allows for a variety of different characteristics
for the client/server communication, in particular "character mode" vs
"line mode" - in the former case, the client sends character-by-character
to the server, which is responsible for echo, line editing etc, whereas
in the latter the client does the echo/editing, and sends only complete
lines to the server.

If the client connects to an actual telnet server (i.e. something that
speaks the telnet protocol), these things are negotiated, usually ending
up with "character mode" being chosen, as that is most useful with
respect to the actual applications being run "behind" the telnet server.

If the client connects to something that isn't a telnet server, there
can be no such negotiation of course, and the client has to make an
"intelligent" choice of its own - and of course the Unix telnet client
is more intelligent than the Windows one:-), chosing line mode rather
than character mode in this case, since this makes it much easier to
"talk" to whatever strange thing is at the other end (e.g. an SMTP
server, or an Erlang program:-) - you see what you type, can use
delete/backspace to correct typing errors etc.

That being said, most telnet clients allow you to change these modes
manually - with the typical Unix client, you type the escape character
(normally ctrl-]), and can then tell the client to change mode with
something like 'mode character' or 'mode line'. I assume (perhaps
optimistically:-) that you can do this with the standard Windows client
too, but I wouldn't know how - in any case it can't be fixed by the
Erlang program at the other end, unless it actually speaks the telnet
protocol (which is probably not what you wanted it to do:-).

Bottom line: Your Erlang server will get the data from the socket in
whatever batches the client decides to send them (more or less -
depending on timing, data volume etc e.g. multiple packets may be
received as one chunk of data - TCP doesn't preserve packet boundaries).

--Per Hedeland

More information about the erlang-questions mailing list