gen_server

Björn Bylander bjorn.bylander@REDACTED
Fri Aug 2 15:05:46 CEST 2002


Hi,

On 2002-03-22, Francesco Cesarini wrote:
> 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.

Is there any way to design a process using passive sockets so that it 
supports code replacement without using shortish timeouts to recv?
The process would mostly spend time in a passive recv, much like you 
describe in the last paragraph.

> 
> 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.
>>

/Björn





More information about the erlang-questions mailing list