The SO_KEEPALIVE option tells the TCP stack to occasionally (every 2 hours or so) send a packet if there has been no other traffic; this is used for detecting peers that drop off the network due to a server crash, power failure, etc. It is unrelated to what you're trying to do.
OK, now -- if you open a Socket in one process, and a ServerSocket in another, they ought to remain connected indefinitely. If they're closing, it's because the software on one end or the other is closing it. Maybe you could give us more details of exactly what you're seeing.