Heartbeat question

Version 1
    This document was generated from CDN thread

    Created by: Vladimir Banker on 18-02-2009 06:33:44 PM
    Hi !
    for prevent socket to be closed I need to send heartbeat event.
    I put it into CExecInput::recvMsg method after I got OPEN_CONF and HEARTBEAT_CONF events.
    For example:
    CMsgBase &HeartbeatMsg = CHeartbeatReq();
    CRS_BYTE *bytes = HeartbeatMsg.pack();
    send via socket ...

    If I in same time I make command from command line like setagentstatereq, I get always exception(Access violation writing location ...)  in pack() method.
    I think it because of that I create messages(one for setagentstatereq and second for HeartbeatReq) in different threads. But all messages are different objects!!!

    Is it mean that all requests should be sequent one by one and also created in one thread for example in main thread?

    Subject: RE: Heartbeat question
    Replied by: David Lender on 18-02-2009 07:56:32 PM
    Sorry, I can't provide guidance on multi-threaded socket programming, only in the the CTI Message protocol.  I do wonder why you would send a HeartBeatReq after a HeartBeatConf?  You could add to the sample a HB command which would send a HEARTBEAT_REQ to which the CTI Server will respond with a HEARTBEAT_CONF or a FAILURE_CONF.

    Subject: RE: Heartbeat question
    Replied by: Vladimir Banker on 18-02-2009 09:14:02 PM
    1.As I mentioned before the exception happened when I call pack method from diffrent threads and not in socket stuff.
    2.Regarding HB, I wanted to send HeartbeatReq automatically in background to prevent socket to be closed, after OPEN_CONF I started to send HB and after that on every HEARTBEAT_CONF I sent new HEARTBEAT_REQ. Is it wrong,what is your suggestion to HB?

    Subject: RE: Heartbeat question
    Replied by: Fahim Siddique on 06-03-2009 02:14:02 PM
    Ideally you should send HB, after every 20 secs and thats regardless of whether you receive HB confirmation (HEARTBEAT_CONF) or not . Also keep a count of every HB that you send (HEARTBEAT_REQ), once you recieved HB Confirmation offset the count by one (i.e decrement it by one) ; that will make you keep a count of missed HB confirmations. Once there are enough missed HB confirmation (i.e. your count is say 3 or more)  you should drop your socket connect and try to reconnect.