Metrologic Optimus S Programming Manual page 160

"c" programming guide
Table of Contents

Advertisement

154
"C" Programming Guide For Optimus S/R
SOCKET s;
Example
struct sockaddr_in name;
s = socket (PF_INET, SOCK_STREAM, TCP);
if (s < 0) {
printf ("SOCKET allocation failed");
...................
}
memset (&name, 0, sizeof (name));
name.sin_family = AF_INET;
name.sin_port = htons (3000);
if (bind (s, (struct sockaddr*) &name, sizeof (name)) < 0) {
printf ("Error in Binding on socket: %d", s);
...................
}
if (listen (s, l) {
printf ("Error in Listening on socket: %d", s);
...................
}
Description
This routine is used with connection-oriented socket type SOCK_STREAM; it
is part of the sequence of routines that are called to perform a passive open.
listen() puts the bound socket in a state in which it is listening up to a backlog
number of connection requests from clients.
The socket is put into passive open where incoming connection requests
are acknowledged and queued pending acceptance by the accept() process.
This routine is typically used by servers that can have more than one
connection request at a time. If a connection request arrives and the queue
is full, the client will receive an error.
If there are no available socket descriptors, listen() attempts to continue to
function. When descriptors become available, a later call to listen() or
accept() will refill the queue to the current or most recent backlog, if
possible, and resume listening for incoming connections.
If listen() is called on an already listening socket, it will return success
without changing the backlog. Setting the backlog to 0 in a subsequent call
to listen() on a listening socket is not considered a proper reset, especially
if there are connections on the socket.
Return
If successful, it returns 0.
On error, it returns -1.
The global variable errno is set to indicate the error condition encountered.
See Also
accept, connect

Advertisement

Table of Contents
loading

This manual is also suitable for:

Optimus r

Table of Contents