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
Note that checking the state of the PHY only helps with a cable being disconnected locally. It doesn't tell what happens on the other side of the first switch, and there may be a huge number of network routers between your unit and the other end.
KeepAlive - or regular own messages - will catch even these errors. But since regular transfers represents a form of polling, the polling frequency decides how fast you will notice a problem.
Note also that in many situations, TCP/IP will be able to retransmit and keep the connection alive even if a user shortly disconnects/reconnects a wire or reboots a router. Having too hard requirements - for example by looking for ping times - may be counterproductive.
"Note that checking the state of the PHY only helps with a cable being disconnected locally."
A very valid point.
I'd also add that if you really need to check for broken connections quickly then TCP/IP over Ethernet is not always the most suitable anyway. Like many other communication mediums, Ethernet is, by definition, non-deterministic. Errors can (and quite often do) occur, which cause retransmissions and therefore delays.
I know what you mean. but, indeed my project works based on MODBUS TCP and here is a function to process raw data and makes MODBUS packet for transmission and for receiving data, process MODBUS packet to main data and commands.
TCP RFC said as a keepalive packet you can send a packet with no any data or with garbage data
RL-ARM can't send a packet with no data and if I try to send data as a keepalive packet the MODBUS program on the other side (client side) couldn't pass it and throw an exception. I'm using free license of ASComm.net and has such a problem.
I know here is not website of MODBUS but I've used OPEN MODBUS and because of that MODBUS organization doesn't help me.
this project is about my dissertation.
if anybody knows how could I implement keepalive with these limitations, I'd appreciate him.
thanks.
Why should any MODBUS organisation help you? Your problem isn't with any error in any standard.
Create dummy reads then. Ask the client once/second even if you only need data once/minute or whatever.
"TCP RFC said as a keepalive packet you can send a packet with no any data or with garbage data"
That's not quite how I remember it being described!?
Data is data is data. How can you send garbage data? How would any TCP stack know that an application is sending garbage data as opposed to non-garbage data?
TCPnet is definitely NOT unusual in NOT providing a facility to issue keepalive packets at will from within an application.
you're right IB Shy but if I myself have implemented the client side. for example I can send "hello client" and if in client side get such a packet I'd ignore it.
but if I try to send packet with data included AScomm.net give me an exception.
(I want to send packet without data to check the reaction of ASComm.net ... but, doesn't matter)
anyway
thank guys for your responses
your posts were very useful for me
thanks thanks thanks