Hi
I've used At91sam7x512 and keil sample codes for TCP connection but here is a kind of problem when I try to disconnect my board in my tcp_callback routine I'll get TCP_EVT_CLOSE condition and here I called tcp_close(soc)
when I use tcp_get_state before tcp_close the result is 10 (TCP_STATE_CONNECT) and after that it's 255 (!!!)
and if I wait for 2 or more minutes my tcp_callback have been called again but with TCP_EVT_ABORT condition.
during this time gap, I'm in listening mode but nobody can connect to my device.
below code is a part of my work and I used printf to get state of tcp in different positions:
case TCP_EVT_CLOSE: printf("1:%d\r\n",tcp_get_state(soc)); tcp_close(soc); tcp_release_cocket(soc); printf("2:%d\r\n",tcp_get_state(soc)); initializetcp(); . . . case TCP_EVT_ABORT: printf("3:%d\r\n",tcp_get_state(soc)); tcp_abort(soc); tcp_release_cocket(soc); printf("4:%d\r\n",tcp_get_state(soc)); initializetcp(); . . .
and in initializetcp routine I try to get socket and listen. and I've used tcp_abort instead of tcp_close in TCP_EVT_CLOSE condition but they were the same and the problem was exist
and I've got such a result from hyperteminal:
1:10 2:255
(after 2 minute)
3:8 4:255
although when I try to close my program in PC there is no any problem but when my application program throw an exception such problem will occur.
what's going wrong here?
thanks in advance
thanks IB Shy
I tried to read PHY status register ... but it gave me zero as a result ... but something here was dropped out and that was setting PHY to MDI enable... I've forgot it and now with such a routine works properly:
unsigned short int status; MDI_Enable(); status=Read_PHY(0x10); if ((status & 1)) printf("lan is connected\r\n"); else printf("lan has been disconnected\r\n"); MDI_Disable();
here, I could recognize LAN link status very fast.
and about keepalive: Do you agree with keepalive method ,or not? because I've read RFC for TCP and keepalive in this document was not a good method.
I need to know the connection is still alive or not.
with these methods which you said (reading the PHY status and moving the port closing routine to main process), connection is reliable enough but I want to prevent any unexpected problems.
How can I send a TCP packet with zero lenght of data?
thank thank thank
"Do you agree with keepalive method ,or not?"
It really does depend on the requirements. For a connection that is expected to stay alive for a long time with long gaps in the communication, it can be useful. If data is being sent/received with gaps shorter than the keepalive rate then there is little point in having the keepalives. If you want the connection to tidily close when inactive, then keepalives would need to be disabled anyway.
"How can I send a TCP packet with zero lenght of data?"
As far as I am aware, you cannot send a TCP packet of zero length using TCPnet, but that should not be a requirement ...
Technically, when you send data from an application over TCP it is in a stream and the fact that the data is sent in packets should not be important.