user1255454
user1255454

Reputation: 699

Why do my sockets stop transfering?

Ok let me be clear. I'm using TCP and that should mean a connection shouldn't interrupt unless closed or due to network problems.

So here's my issue:

Utilizing my sockets works perfectly.

After 5 - 10 min of innactivity they stop responding (the connection is still alive [checked with netstat -n]).

It tells me that data is send (but the other side doesn't receive it and I'm sure it waiting for it.)

If I keep sending, eventually it will give me WSA error 10038 (invalid socket handle).

EDIT after a few more tries of sending, it gave me error 10058 (An established connection was aborted by the software in your host machine. )

I'm confused completely. I haven't closed the socket nor done anything to it other than inactivity. If I use it nonstop for 10 - 20 minutes, it works perfectly.

Upvotes: 1

Views: 504

Answers (2)

arayq2
arayq2

Reputation: 2554

With error 10058, it's practically certain that a gateway (a proxy, or a firewall, or a router, with or without NAT) is timing out its relay of your connection.

Basically, you are not directly connected with your peer. Instead, the gateway is in between, and explicitly transfering data between its connection with you and its connection with your peer. Since sockets are a limited resource, the gateway has an eviction policy where it shuts down what look like inactive connections. If you look dead, boom, you are dead.

Your only option is to remain active, which typically means working in some kind of "heartbeat" into your application protocol. Nasty, but them's the breaks.

Unless you really know what you are doing, do not play around with TCP's SO_KEEPALIVE.

Upvotes: 3

Thomas
Thomas

Reputation: 182038

A NAT firewall may be eating your connection without telling you. Try enabling TCP keepalive.

Upvotes: 1

Related Questions