So, ping is IGMP and does not create a connection to communicate like a protocol using sockets. Therefore it merely means that the IP stacks are working on both sides and that there's a capability to communicate still available.
This socket is probably from some service or application; the question becomes what app or service is using the socket. There's a keep alive attribute, SO_KEEPALIVE which can be applied if you're the one controlling the socket calls. In a SOCK_STREAM I believe that there is also a condition where if one side transmits and it times out (TCP does not receive an ACK - because it is a connection-oriented, reliable protocol) then the original transmitter determines that the socket is unavailable. Therefore if the remote side shut down it's service or application, thus closing the socket on their side, it would lead to a potential error, or not really error but report on your side saying things like what you're seeing.
To answer your question about how to use the keepalives, I pretty much always have to look it up, so I did and this one seems reasonable, there's a whole document, this link points to the section where there's a code example. There are however instructions for command line options if you're establishing a socket from outside a program. TCP Keepalive HOWTO