[erlang-questions] A small question about TCP Socket of Erlang

Ngoc Dao <>
Sun Nov 29 05:06:48 CET 2009


I see, the your confusion is you have "receive", but you don't know
where the messages come from. You think messages received at the
server are sent from the client and and vice versa, but actually they
are not.

Try a simpler experiment:
* Run only your Erlang server, do no run your Erlang client.
* Use "telnet" program as a client to connect to your Erlang server.

You will see that messages received at the server are sent from the
server itself, from an underlying process spawned by the API library.


On Sun, Nov 29, 2009 at 12:15 PM, Yan Yan <> wrote:
> Hi Ngoc,
>
> Thanks for your reply. But I am still confused on the message passed between
> ends.
>
> Is the message passed from client to server {tcp, SocketOnClient, BinData},
> while server to client {tcp, SocketOnServer, BinData}? I am quite confused
> why there is a match within receive...end block of both ends, since
> SocketOnClient and SocketOnClient do not match.
>
> Sincerely,
>
> Yan
> 2009-11-28
> ________________________________
> From: Ngoc Dao
> Time:  2009-11-28 16:02:34
> To: erlang-questions
> Fw:
> Subject: Re: [erlang-questions] A small question about TCP Socket of Erlang
>
>> Why is there a match? SocketOnClient =:= SocketOnServer? Do server and client share the same socket after connection is set?
> No. SocketOnServer in step 3 is for matching with SocketOnServer in
> step 2. SocketOnServer and SocketOnClient are just values and
> independent. To see their values, use io:format("~p~n",
> [SocketOnServer]) and io:format("~p~n", [SocketOnClient]).
> I think you're confused because of the resemblance of the code for
> server and the code for client. But actually this is the beauty of the
> design of the API.
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org


More information about the erlang-questions mailing list