开发者

How to handle Socket Exception ideally?

I'm using socket fo开发者_JS百科r chat application and I get SocketException unexpectedly. How this exception should ideally be handled? I'm currently simply reconnecting socket. How to make sure my socket is live on application level? I'm aware of method setKeepAlive


A SocketException indicates an error on the network level, usually a TCP/IP error.

Handle this one of two ways: let your application decide if this is a constant issue (firewall, bad connection, etc...) and notify the user, or if this is temporary and can be restored, in which case you should try to reconnect to the socket.

setKeepAlive() has nothing to do with restarting the connection. It only keeps sending keep-alive packets so the connection will not be terminated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜