Metrologic Optimus S Programming Manual page 153

"c" programming guide
Table of Contents

Advertisement

connect
Purpose
To initiate a connection on a socket.
Syntax
int connect (SOCKET s, struct sockaddr *name, int namelen);
s
name
namelen
Example
SOCKET s;
struct sockaddr_in name;
struct hostent *phostent;
s = socket (PF_INET, SOCK_STREAM, TCP);
if (s < 0) {
}
memset (&name, 0, &sizeof (name));
name.sin_family = AF_INET;
name.sin_port = htons (3000);
phostent = gethostbyname ("server1.Metrologic.com.tw");
if (!phostent) {
}
memcpy (&name.sin_addr, phostent->h_addr_list[0], 4);
if (connect (s, (struct sockaddr*) &name, sizeof(name)) < 0) {
Description
This routine establishes a connection to a specified socket.
It performs an active open (client mode), allowing a client application to
establish a connection with a remote server.
When it completes successfully, the socket is ready to send/recv data.
Return
If successful, it returns 0.
On error, it returns -1.
The global variable errno is set to indicate the error condition encountered.
Chapter 3 Terminal Specific Function Library
Descriptor identifying a socket
Pointer to a sockaddr structure containing the remote IP
address and port number
Integer specifying the length of name
printf ("SOCKET allocation failed");
...................
printf ("Can not get IP from DNS server");
...................
printf ("Error in Establishing connection");
...................
}
147

Advertisement

Table of Contents
loading

This manual is also suitable for:

Optimus r

Table of Contents