einval error when gen_tcp:recv after successful gen_tcp:send

klacke@REDACTED klacke@REDACTED
Thu Dec 9 19:03:13 CET 2004


On Thu, Dec 09, 2004 at 04:15:19PM +0100, Ericsson, Bjorn wrote:


>    when the client tries to use gen_tcp:recv. This is where it receives
>    {error, einval}.
> 
> 
>    get_response(Request, Port) ->
>    %%% Setup connection %%%
>      case gen_tcp:connect("localhost", Port,
>                                   [list, {packet, 0},{reuseaddr, true}])



Your socket is (as they are by default) in active mode, this means
that it's not allowed to call recv() on the socket, instead of
actively recv()'ing your process will get messages on the form of:

        {tcp, Socket, Data}


So either you have tp specify {active, false} as a socket option
when you create the socket, or rewrite your code to receive
messages instead of actively recv() 'ing.

recv() and {active , false} has the advantage that you
get flow control for free (through TCP/IP) whereas 
{active, true} has the advantage that it's more flexible.


Read erlang man pages for 'gen_tcp' and 'inet' several times.


/klacke


-- 
Claes Wikstrom                        -- Caps lock is nowhere and
http://www.hyber.org                  -- everything is under control          



More information about the erlang-questions mailing list