| Description | The listen function sets the specified socket in a listening mode. Before calling the listen function, the bind function must be called. The argument sock specifies a socket descriptor returned from a previous call to socket. The argument backlog specifies a maximum number of connection requests that can be queued. The listen function is in the RL-TCPnet library. The prototype is defined in rtl.h. note - You must call the socket function before any other function calls to the BSD socket.
- If a negative number is returned, it represents an error code.
|
| Example |
#include <rtl.h>
__task void server (void *argv) {
/* Server task runs in 2 instances. */
SOCKADDR_IN addr;
int sock, sd, res;
int type = (int)argv;
char dbuf[4];
while (1) {
sock = socket (AF_INET, type, 0);
addr.sin_port = htons(1001);
addr.sin_family = PF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
bind (sock, (SOCKADDR *)&addr, sizeof(addr));
if (type == SOCK_STREAM) {
listen (sock, 1);
sd = accept (sock, NULL, NULL);
closesocket (sock);
sock = sd;
}
while (1) {
res = recv (sock, dbuf, sizeof (dbuf), 0);
if (res <= 0) {
break;
}
procrec ((U8 *)dbuf);
}
closesocket (sock);
}
}
|