gen_server

Francesco Cesarini francesco@REDACTED
Fri Mar 22 11:57:43 CET 2002


Hi Yurii,
When your client makes a call to the server, it times out as your server 
is busy listening to the socket in passive mode (It sounds like you 
specified {active, false} and are retrieving your messages using recv). 
The gen_server:call function has a default timeout of 5 seconds, after 
which it crashes with the reason {timeout, {gen_server,....}}

A solution to your problem is to have your socket run in active mode 
specifying {active, true}. This will result in all the incoming packages 
to be send to the server in the format {tcp, Socket, Data}. You would 
have to handle them in your handle_info call back function.

Another (and more common solution) is to have one process listen to the 
socket, parse the messages, and forward them to the server which handles 
the requests from the client. In this case, the server should be able to 
handle many simultaneous clients.

Hope this helps.

Regards,
Francesco
--
http://www.erlang-consulting.com

Yurii A. Rashkovskii wrote:

>Ladies and Gentlemen,
>
>I have a question concerning gen_server and related things. 
>
>
>I have supervised gen_server running and usual process that listens
>socket, receives messages, parses them, pass to that gen_server and then
>returns replies back. Also I have another client application that sends
>messages to gen_server directly w/ gen_server:call, do not using that
>TCP wrapper. Then, if only of these clients is working with gen_server,
>all is ok. But if there both of these clients, behaviour significantly
>changes - for example, application that connects directly by
>gen_server:call fails w/ {'EXIT', { timeout, .
>
>What can be the problem of two (and probably more) clients working w/
>gen_server simultaneously?
>
>I understand that question looks very indefinably, so I need any advices
>:-)
>
>Thank you in advance.
>






More information about the erlang-questions mailing list