I am writing simple program to control device through TCP port. Program was working but connection close automatically after time out. To hold the connection I try to use TCP_TYPE_KEEP_ALIVE flag, but it does not work. Did someone TCP connection that stay open until client send requests?
If your Application needs to know that it has a live end-to-end connection to its peer, then you need to design that into your Application protocol; eg, with some kind of "heartbeat" message exchange...
Connection from the microcontroller closes automatically, no matter how often client on a computer send requests. Requests from the computer was sending many times per second, timeout is set at 2 minutes and after 2 minutes the connection from the microcontroller closes. Probably I should set KEEP_ALIVE flag, but it does not work.
Does it?
Are you sure that the microcontroller and/or the client aren't explicitly closing the connection?
Is this a standard protocol (eg, HTTP), or one of your own devising?
Yes. It is simple TCP port 1001:
__task void Ether() {
os_itv_set(RL_1MS*20);
init_TcpNet();
// Initialize TCP Socket and start listening
socket_tcp = tcp_get_socket (TCP_TYPE_SERVER, 0, 30, tcp_callback); // | TCP_TYPE_KEEP_ALIVE
if (socket_tcp != 0)
tcp_listen(socket_tcp, PORT_NUM);
while (1) {
os_itv_wait(); // wait timer event
timer_tick();
main_TcpNet();
}
in
U16 tcp_callback (U8 soc, U8 evt, U8 *ptr, U16 par) {
I just use
case TCP_EVT_DATA:
to get and send data.
"I just use
to get and send data."
Are you sending data from within the callback? You shouldn't be.