[erlang-questions] Mini Server does not reciv

Steve Vinoski vinoski@REDACTED
Thu Aug 29 16:47:55 CEST 2013


On Thu, Aug 29, 2013 at 8:11 AM, Schneider <js@REDACTED> wrote:

> Hi List,
>
> I tried playing around with  a baby example of a server, just printing the
> data it receives.  But I don't get any output:
>
> the Code:
>
>  -module(mini_web_srv).
>>
>> -export([start/0,send/0]).
>>
>> start() ->
>>     { ok, Listen } = gen_tcp:listen(8080,
>>                    [binary,
>>                     {packet, 4},
>>
>
<snip>


> send_data(Data) ->
>>     {ok, Send} = gen_tcp:connect("localhost", 8080,[binary, {packet, 0}
>> ]),
>>     gen_tcp:send(Send, Data).
>>
>
It fails because you open the server with {packet,4} and the client with
{packet,0}. The client and server must agree on the packet value for them
to be able to communicate successfully. To make it work you can either
remove the packet option entirely from both client and server, or set the
client to {packet,4} to match the server.

You might want to look at https://gist.github.com/vinoski/4996859 to see an
example of a very small yet operational web server.

--steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130829/b532b2c2/attachment.htm>


More information about the erlang-questions mailing list