The EZASOKPC PL⁄I sample program is a client program that
shows you how to use the following calls provided by the call socket
interface:
- CONNECT
- GETPEERNAME
- INITAPI
- READ
- SHUTDOWN
- SOCKET
- TERMAPI
- WRITE
/*********************************************************************/
/* */
/* MODULE NAME: EZASOKPC - THIS IS A VERY SIMPLE IPV4 CLIENT */
/* */
/* Copyright: Licensed Materials - Property of IBM */
/* */
/* "Restricted Materials of IBM" */
/* */
/* 5694-A01 */
/* */
/* (C) Copyright IBM Corp. 1994, 2002 */
/* */
/* US Government Users Restricted Rights - */
/* Use, duplication or disclosure restricted by */
/* GSA ADP Schedule Contract with IBM Corp. */
/* */
/* Status: CSV1R4 */
/* */
/*********************************************************************/
EZASOKPC: PROC OPTIONS(MAIN);
/* INCLUDE CBLOCK - common variables */
% include CBLOCK;
ID.TCPNAME = 'TCPIP'; /* Set TCP to use */
ID.ADSNAME = 'EZASOKPC'; /* and address space name */
open file(driver);
/*********************************************************************/
/* */
/* Execute INITAPI */
/* */
/*********************************************************************/
call ezasoket(INITAPI, MAXSOC, ID, SUBTASK,
MAXSNO, ERRNO, RETCODE);
if retcode < 0 then do;
msg = 'FAIL: initapi' || errno;
write file(driver) from (msg);
goto getout;
end;
/*********************************************************************/
/* */
/* Execute SOCKET */
/* */
/*********************************************************************/
call ezasoket(SOCKET, AF_INET, TYPE_STREAM, PROTO,
ERRNO, RETCODE);
if retcode < 0 then do;
msg = blank; /* clear field */
msg = 'FAIL: socket, stream, internet' || errno;
write file(driver) from (msg);
goto getout;
end;
sock_stream = retcode; /* save socket descriptor */
/*********************************************************************/
/* Execute CONNECT */
/* */
/*********************************************************************/
name_id.port = 8888;
name_id.address = '01234567'BX; /* internet address */
call ezasoket(CONNECT, SOCK_STREAM, NAME_ID,
ERRNO, RETCODE);
if retcode < 0 then do;
msg = blank; /* clear field */
msg = 'FAIL: connect, stream, internet' || errno;
write file(driver) from (msg);
goto getout;
end;
/*********************************************************************/
/* */
/* Execute GETPEERNAME */
/* */
/*********************************************************************/
call ezasoket(GETPEERNAME, SOCK_STREAM,
NAME_ID, ERRNO, RETCODE);
msg = blank; /* clear field */
if retcode < 0 then do;
msg = 'FAIL: getpeername' || errno;
write file(driver) from (msg);
end;
else do;
msg = 'getpeername =' || name_id.address;
write file(driver) from (msg);
end;
/*********************************************************************/
/* */
/* Execute WRITE */
/* */
/*********************************************************************/
bufout = message;
nbyte = length(message);
call ezasoket(WRITE, SOCK_STREAM, NBYTE, BUFOUT,
ERRNO, RETCODE);
msg = blank; /* clear field */
if retcode < 0 then do;
msg = 'FAIL: write' || errno;
write file(driver) from (msg);
end;
else do;
msg = 'write = ' || bufout;
write file(driver) from (msg);
end;
/*********************************************************************/
/* */
/* Execute READ */
/* */
/*********************************************************************/
nbyte = length(bufin);
call ezasoket(READ, SOCK_STREAM,
NBYTE, BUFIN, ERRNO, RETCODE);
msg = blank; /* clear field */
if retcode < 0 then do;
msg = 'FAIL: read' || errno;
write file(driver) from (msg);
end;
else do;
msg = 'read = ' || bufin;
write file(driver) from (msg);
end;
/*********************************************************************/
/* */
/* Execute SHUTDOWN from/to */
/* */
/*********************************************************************/
getout:
how = 2;
call ezasoket(SHUTDOWN, SOCK_STREAM, HOW,
ERRNO, RETCODE);
if retcode < 0 then do;
msg = blank; /* clear field */
msg = 'FAIL: shutdown' || errno;
write file(driver) from (msg);
end;
/*********************************************************************/
/* */
/* Execute TERMAPI */
/* */
/*********************************************************************/
call ezasoket(TERMAPI);
close file(driver);
end ezasokpc;
Figure 1. EZASOKPC
PL/1 sample client program for IPv4