| Description | The bind function assigns a name to an unnamed socket. The name represents the local address and port of the communication end point. The argument sock specifies a socket descriptor returned from a previous call to socket. The argument addr is a pointer to the SOCKADDR structure containing the local address and port of the socket. The argument addrlen specifies the length of the SOCKADDR structure. The bind 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);
}
}
|