| Example |
#include <rtl.h>
U8 tcp_soc;
U16 tcp_callback (U8 soc, U8 event, U8 *ptr, U16 par) {
/* This function is called on TCP event */
..
switch (event) {
case TCP_EVT_CONREQ:
/* Remote host is trying to connect to our TCP socket. */
/* 'ptr' points to Remote IP, 'par' holds the remote port. */
..
/* Return 1 to accept connection, or 0 to reject connection */
return (1);
case TCP_EVT_ABORT:
/* Connection was aborted */
..
break;
case TCP_EVT_CONNECT:
/* Socket is connected to remote peer. */
..
break;
case TCP_EVT_CLOSE:
/* Connection has been closed */
..
break;
case TCP_EVT_ACK:
/* Our sent data has been acknowledged by remote peer */
..
break;
case TCP_EVT_DATA:
/* TCP data frame has been received, 'ptr' points to data */
/* Data length is 'par' bytes */
..
break;
}
return (0);
}
void main (void) {
init ();
/* Initialize the TcpNet */
init_TcpNet ();
tcp_soc = tcp_get_socket (TCP_TYPE_SERVER, 0, 30, tcp_callback);
if (tcp_soc != 0) {
/* Start listening on TCP port 80 */
tcp_listen (tcp_soc, 80);
}
while (1);
/* Run main TcpNet 'thread' */
main_TcpNet ();
..
}
}
|