I have a simple program that implements a TCP server.
Here is the framework:
- main() starts the task that creates timer_task and task_tcp. - timer task simply calls the timer_tick() every 100 ms - tcpTask simply does nothing. Note:The TCP actually does nothing, but I have prevented the "idle connection" timeout by setting it in tcp_get_socket to 65536;
int main (void) { init_TcpNet(); os_sys_init (task_init); } __task void task_init (void) { os_tsk_prio_self(100); os_tsk_create (timer_task, 2); tskTcp = os_tsk_create_user (task_TCP, 1, &tcp_stack, sizeof(tcp_stack)); os_tsk_delete_self(); } __task void timer_task (void) { os_itv_set (10); while (1) { os_itv_wait (); timer_tick (); iTimer++; } } U8 state, state2; __task void task_TCP (void) { initializeAllBuffers(); Connect(1); // this function simply gets the socket and starts listening while(1) { main_TcpNet(); } }
Now, here is the problem - When I try to connect to the server with my Windows client application, the connection is successfully established. After about a minute (iTimer gets to around 600), the connection breaks and my client application throws WinSock error 10053 "Software caused connection abort.".
If, on the other hand, I start the server and then try to connect AFTER the iTimer has gone over 600, the connection stays open without crashing (not even after 30 minutes).
If I try to connect somewhere between iTimer = 0 and iTimer = 600, the connection still drops somewhere around 600.
What could be the cause of such strange behaviour? Why would the connection drop at all? The timeout is not the problem here, and the idleness is not the problem also. I have tried this with some communication happening but it drops at around 600 anyway. (I have excluded the communication for brevity since it happens even if there is no communication between client and the server).