EasyManua.ls Logo

Intermec Antares 2420 - Page 167

Intermec Antares 2420
480 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Co de 39
Nugget
Operating the Terminal in a Network
4-33
4
CLIENT.CPP Sample Application for a TCP/IP Direct Connect Network
#include <windows.h>
#include <stdio.h>
#include "d:\class\Utils.h"
// our application uses a fixed port number
const unsigned short SERVER_PORT = 6000;
const unsigned short CLIENT_PORT = 6001;
// we will default to the local host machine
// unless argv[1] has a hostname
const char SERVER_HOSTNAME[] = "ncm";
int main(int argc, char *argv[])
{
// turn on the socket library for this process
WSADATA wsad;
int error = WSAStartup(MAKEWORD(1,1), &wsad);
if (error != 0)
ErrorMessage("WSAStartup", WSAGetLastError());
// create an unitialized connection-oriented socket
SOCKET connection;
connection = socket(PF_INET, SOCK_DGRAM, 0);
if (connection == INVALID_SOCKET)
ErrorMessage("socket", WSAGetLastError());
// lookup the IP address of the requested host
HOSTENT *phostent = gethostbyname(argc == 2 ? argv[1] : SERVER_HOSTNAME);
if (phostent == 0)
ErrorMessage("gethostbyname", WSAGetLastError());
// define a SOCKADDR to contain the IP address of the
// server and the port number of our application
SOCKADDR_IN serverAddress;
memset(&serverAddress, 0, sizeof(serverAddress));
serverAddress.sin_family = PF_INET;
serverAddress.sin_port = htons(SERVER_PORT);
memcpy(&serverAddress.sin_addr, phostent->h_addr_list[0], phostent->h_length);
// Bind a well known port of 6000 to the socket
SOCKADDR_IN clientAddress;
memset(&clientAddress, 0, sizeof(clientAddress));
clientAddress.sin_family = PF_INET;
clientAddress.sin_port = htons(CLIENT_PORT);
clientAddress.sin_addr.s_addr = htonl(INADDR_ANY);
if(!(bind(connection, (LPSOCKADDR)&clientAddress, sizeof(clientAddress))
==0))
{
ErrorMessage("bind", WSAGetLastError());
}

Table of Contents

Other manuals for Intermec Antares 2420

Related product manuals