Archived

This forum has been archived. Please start a new discussion on GitHub.

Bi-directional conn. reestablishment

Hi,

I've got a client that makes a bi-directional connection with a server. I thought that I had found a way to detect when the server went down and have the client properly reestablish the connection. This seemed to fail the other day in production, though I have yet to get it to fail in test.

What I do on the client is have a thread that pings the server every so often. After the ping, I check to see if the adapter registered on the connection is NULL, if so, I reset the adapter and register the callback object with the server. Should this ALWAYS work? Any suggestions or thoughts appreciated.
ScheduleVersionIFPrx ver;
  Ice::Identity ident;
  IceUtil::Monitor<IceUtil::Mutex>::Lock lock(m_connMonitor);

  Ice::ObjectAdapterPtr adapter = m_server->adapter();
  try {
    ident.name = IceUtil::generateUUID();
    adapter->add(m_listener, ident);
    m_scheduleServer->ice_connection()->setAdapter(adapter);
    m_scheduleServer->regTxListenerIdent(ident, m_listener->lastReceived());
//
// Do a ping every once in a while to test the state of the connection.  If the
// connection is the same as before, nothing happens.  If the connection was
// reestablished, set the adapter and register the listener.  If the connection
// can't be reestablished (server down), throw and exception and let everything
// start over.
//
    while (true) {
      m_scheduleServer->ice_ping();
      if (m_scheduleServer->ice_connection()->getAdapter() == 0) {
        m_scheduleServer->ice_connection()->setAdapter(adapter);
        m_scheduleServer->regTxListenerIdent(ident, m_listener->lastReceived());
      }
    }
  }

Comments

  • benoit
    benoit Rennes, France
    Hi,

    You should add a call to sleep in your loop, otherwise you'll continuously ping the server. In any case, I can't think of any reasons why this wouldn't work. However without more information about the failure it's hard to say what could have gone wrong.

    Cheers,
    Benoit.
  • Thanks

    There was a sleep in there. I must have removed it in haste when I posted the code. As long as this *should* work, I won't fret.

    Thanks again,