× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



"Could you do a socket connection?"

That's exactly what I did using one of Scott Klement's client side socket
programs. Here is the code. The copybook containing the pr specs is first.


//---------------------------------------------------------------------
//š Management Information Systems

//---------------------------------------------------------------------

//*********************************************************************
// Program Description/Documentation€
//
// DATE: 1/25/10
// DESCRIPTION: Check for internet availability.

//*********************************************************************
// DEFINITION SPECS

//*********************************************************************
D ZNETISUP_Val S 1
// Check for internet availability
D ZNETISUP PR 1
D P#Site 255 VALUE
D P#Port 5 0 VALUE
D P#Timeout 5 0
VALUE




H/Copy Qrpglesrc,OITHSPEC

Note: This is the content of OITHSPEC
ctl-opt option(*nodebugio:*srcstmt);
ctl-opt nomain;
ctl-opt debug(*input);


//---------------------------------------------------------------------
//š Management Information Systems

//---------------------------------------------------------------------

//*********************************************************************
// Program Description/Documentation€
//
// AUTHOR: Gerald Kern
// DATE: 1/25/10
// DESCRIPTION: Check for internet availability by attempting to
// create a socket connection to google.com on port 80. Other sites
// using other ports may be passed as parameters. A timeout value
// in seconds allows you to specify how long to wait to connect.
//
// Programs using this function must include the following
// statement in that program's H spec:
// H BNDDIR('SOCKTUT/SOCKUTIL')
//
//šCompile instructions:
//š 1st-Compile this program as a module.

//*********************************************************************
// L O G O F P R O G R A M M O D I F I C A T I O N S

//*********************************************************************
// Date Programmer Description of Modifications
// -------- ----------
----------------------------------------------
//šXX/XX/XX XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

//*********************************************************************
// DEFINITION SPECS

//*********************************************************************
D/copy socktut/qrpglesrc,socket_h
D/copy socktut/qrpglesrc,errno_h
D/copy socktut/qrpglesrc,sockutil_h

// Copybook for ZNETISUP PR specs
D/Copy Qrpglesrc,ZNETISUPPR

// Begin prototype procedure
P ZNETISUP B EXPORT
D ZNETISUP PI 1
D P#Site 255 VALUE
D P#Port 5 0 VALUE
D P#Timeout 5 0 VALUE

//********************************************************
// end of IFS API call definitions
//********************************************************

D sock S 10I 0
D port S 5U 0
D flags S 10I 0
D host s 32A
D addr s 10U 0
D connto S like(sockaddr_in)
D err S 10I 0
D connfds S like(fdset)
D timeout S like(timeval)

D Yes C 'Y'
D No C 'N'

//‘+++++++++++++++++ M A I N L I N E C A L C S +++++++++++++++++
/FREE

If P#Site = *Blanks;
P#Site = 'Google.com';
Endif;
Host = %Trim(P#Site);

If P#Port = *Zero;
P#Port = 80;
Endif;
Port = P#Port;

If P#Timeout = *Zero;
P#Timeout = 60;
Endif;

// Attempt to connect to server...
Exsr Conn_To_Svr;
Return ZNETISUP_Val;
*InLr = *On;
//™++++++++++++++++++++ S U B R O U T I N E S ++++++++++++++++++++

//*********************************************************************
// Conn_To_Svr - Attempt to establish connection with the server.
// Assume connection is up and must prove otherwise...

//*********************************************************************
Begsr Conn_To_Svr;

ZNETISUP_Val = Yes;
//************************************************
// Get the 32-bit network IP address for the host
// that was supplied by the user:
//************************************************
addr = inet_addr(%trim(host));
if addr = INADDR_NONE;
p_hostent = gethostbyname(%trim(host));
if p_hostent = *NULL;
ZNETISUP_Val = No;
LeaveSr;
endif;
addr = h_addr;
endif;

//************************************************
// Create a socket
//************************************************
sock = socket(AF_INET: SOCK_STREAM:
IPPROTO_IP);
if sock < 0;
ZNETISUP_Val = No;
LeaveSr;
endif;

//************************************************
// Put the socket in non-blocking mode:
//************************************************
flags = fcntl(sock: F_GETFL);
flags = flags + O_NONBLOCK;
if fcntl(sock: F_SETFL: flags) < 0;
ZNETISUP_Val = No;
LeaveSr;
endif;

//************************************************
// Create a socket address structure that
// describes the host & port we wanted to
// connect to
//************************************************
p_sockaddr = %addr(connto);

sin_family = AF_INET;
sin_addr = addr;
sin_port = port;
sin_zero = *ALLx'00';

//************************************************
// Start the connection process.
//************************************************
if connect(sock: %addr(connto):
%size(connto) ) < 0;
err = errno;
if err <> EINPROGRESS;
callp close(sock);
ZNETISUP_Val = No;
LeaveSr;
endif;
endif;

//************************************************
// wait up to P#Timeout (seconds) for connection to be made
//************************************************
FD_ZERO(connfds);
FD_SET(sock: connfds);

p_timeval = %addr(timeout);
tv_sec = P#Timeout;
tv_usec = 0;

if select(sock+1: *NULL:
%addr(connfds):
*NULL:
%addr(timeout)) < 0;
err = errno;
callp close(sock);
ZNETISUP_Val = No;
LeaveSr;
endif;

if FD_ISSET(sock: connfds) = *OFF;
callp close(sock);
ZNETISUP_Val = No;
LeaveSr;
endif;

// Here we are connected. We can use send() & recv() to
// send data here...

callp close(sock);
Endsr;
/END-FREE

//*********************************************************************
P E
/define ERRNO_LOAD_PROCEDURE
/copy socktut/qrpglesrc,errno_h


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.