| Description | The tcp_get_state function determines the current state of the TCP socket. Your application can use the tcp_get_state function to monitor the progress when establishing a connection or when closing the connection. The most useful state values are TCP_STATE_CLOSED, TCP_STATE_LISTEN, and TCP_STATE_CONNECT. The argument socket specifies the handle of the socket to get the state of. The tcp_get_state function is in the RL-TCPnet library. The prototype is defined in rtl.h. |
| Example |
#include <rtl.h>
void send_data () {
U8 remip[4] = {192,168,1,100};
U8 *sendbuf;
switch (tcp_get_state (socket_tcp)) {
case TCP_STATE_FREE:
case TCP_STATE_CLOSED:
/* Connection idle, send Connect Request. */
tcp_connect (socket_tcp, Rem_IP, 1001, 0);
break;
case TCP_STATE_CONNECT:
/* We are connected, send command to remote peer. */
if (tcp_check_send (socket_tcp)) {
/* OK, socket is ready to send data. */
sendbuf = tcp_get_buf (2);
sendbuf[0] = BLINKLED;
sendbuf[1] = p2;
tcp_send (socket_tcp, sendbuf, SENDLEN);
}
break;
}
}
|