Added functionality for keepalive msgs but it is not tested yet.