#include <rtl.h>
BOOL tcp_listen (
U8 socket, /* TCP socket to listen with. */
U16 locport ); /* TCP port number to listen at. */
Description
The tcp_listen function opens a socket for incoming
connections by causing the socket to listen at a local TCP port. The
argument socket specifies the handle for the socket to listen
with on the local machine. The argument locport specifies the
TCP port number to listen at.
The tcp_listen function is in the RL-TCPnet library. The
prototype is defined in rtl.h.
note
TCPnet server applications (such as Telnet and HTTP server)
must open a TCP socket for listening.
Only sockets of type TCP_TYPE_SERVER or TCP_TYPE_CLIENT_SERVER
can call the tcp_listen function.
Return Value
__TRUE - if the TCP socket has started listening without
errors
#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 ();
..
}
}
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.