The tcp_get_socket function allocates a free TCP socket.
The function initializes all the state variables of the TCP socket to
the default state.
The argument type specifies the type of the TCP socket.
Socket Type |
Description |
TCP_TYPE_SERVER |
The TCP socket is able to listen on the TCP port for incoming
connections. |
TCP_TYPE_CLIENT |
The TCP socket is able to initiate a connection to a remote
server. |
TCP_TYPE_CLIENT_SERVER |
The TCP socket is able to listen to incoming connections and
to initiate a connection to a remote server. |
TCP_TYPE_DELAY_ACK |
This attribute improves the performance for applications
sending large amounts of data like HTTP server. You can combine
this attribute with the other attributes using the bitwise-or (|)
operation. |
TCP_TYPE_FLOW_CTRL |
The TCP socket is able to control TCP Data Flow. You can
combine this attribute with the other attributes using the
bitwise-or (|) operation. |
TCP_TYPE_KEEP_ALIVE |
The TCP socket is able to send keep-alive packets when
timeout expires. You can combine this attribute with the other
attributes using the bitwise-or (|) operation. |
The argument tos specifies the IP Type Of Service. The most
common value for tos is 0.
The argument tout specifies the idle timeout in seconds.
The TCP connection is supervised by the keep alive timer. When the
connection has been idle for more than tout seconds, TCPnet
disconnects the the TCP connection or sends a keep-alive packet if
TCP_TYPE_KEEP_ALIVE attribute is set.
The argument listener is the event listening
function of the TCP socket. TCPnet calls the listener
function whenever a TCP event occurs. The arguments to the
listener function are:
- socket: TCP socket handle of the local machine.
-
event: Specifies the type of event that occurred as
shown in the table below.
-
ptr: If event is TCP_EVT_DATA, ptr points to a
buffer containing the received data. For all other events,
ptr points to the IP address of the remote machine.
-
par: If event is TCP_EVT_DATA, par specifies the
number of bytes of data received. For all other events, par
specifies the port number used by the remote machine.
TCPnet uses the return value of the callback function
listener only when the event is TCP_EVT_CONREQ. It uses
the return value to decide whether to accept or reject an incoming
connection when the TCP socket is listening. If the
listener function returns 1, TCPnet accepts the
incoming connection. If the listener function returns
0, TCPnet rejects the incoming connection. You can thus define the
listener function to selectively reject incoming
connections from particular IP addresses.
Event Type |
Description |
TCP_EVT_CONREQ |
A Connect Request has been received from a remote client that
wants to connect to the server running on TCPnet. |
TCP_EVT_CONNECT |
The TCP socket has connected to the remote machine. |
TCP_EVT_CLOSE |
The TCP connection has been properly closed. |
TCP_EVT_ABORT |
The TCP connection has been aborted. |
TCP_EVT_ACK |
Acknowledgement has been received from the remote host for
the previously sent data. |
TCP_EVT_DATA |
A TCP data packet has been received. |
The tcp_get_socket function is in the RL-TCPnet library.
The prototype is defined in rtl.h.
note
-
You must call the tcp_get_socket function before any
other function calls to the TCP socket.
-
You must define the listener function to use with
the TCP socket.
-
You must use the TCP_TYPE_KEEP_ALIVE attribute for a
longstanding connection.
|