implement keep connection function