Professional Documents
Culture Documents
listen() Places a listener on the port specified by the bind function Server
connect() Connects a client to the server endpoint specified in the socket address
structure Client
read() Reads data using the socket descriptor returned by the accept function
Client & Server
write() Writes data using the socket descriptor Client & Server
close() Closes the socket descriptor preventing further connection requests Client
& Server
D PtrToOn * Value
D PtrToSAddr * Value
D PtrToSAddr * Value
D PtrToAddrSz * Value
D PtrToBuffer * Value
D PtrToBuffer * Value
D PtrToSAddr * Value
D $$Errno PR * ExtProc('__errno')
D StrError PR * ExtProc('strerror')
** C MACROS (CONSTANTS)
*D AF_INET C Const(2)
D SOCK_STREAM C Const(1)
D UNUSED C Const(0)
D SOL_SOCKET C Const(-1)
D SOL_REUSEADDR C Const(55)
D EACCES C Const(3401)
D EAFNOSUPPORT C Const(3422)
/COPY QRPGLESRC,$SocketsH
* SOCKET ADDRESS STRUCTURE (TCP AND UDP)
D serveraddr DS
D sin_family 5i 0
D sin_port 5u 0
D sin_addr 10u 0
D sin_addrA 4a OVERLAY(sin_addr)
D sin_zero 8a
D Miscellaneous DS
D DspError 4S 0 INZ
D DspErrorA 4A OVERLAY(DspError)
C SELECT
C WHEN Errno = EACCES
C Error3401 DSPLY
C IF (rc < 0 )
C EVAL perrno = $$Errno
C EVAL DspError = Errno
C EVAL pMessage = StrError(Errno)
C EVAL MsgToDsply = DspErrorA + ' ' + Message
C MsgToDsply DSPLY
C ListenError DSPLY
C EVAL *INLR = *ON
C RETURN
C ENDIF
*--------- Accept new connection requests. If rc is greater than zero,
*--------- the returned value is the socket descriptor identifier for
*--------- the client partner that requested the current connection.
C DOW ( Buffer <> '*STOPSVR' )
C EVAL rc = Accept(SDID:%ADDR(serveraddr):%ADDR(
C svaddrlen))
C IF ( rc < 0 )
C EVAL perrno = $$Errno
C EVAL DspError = Errno
C EVAL pMessage = StrError(Errno)
C EVAL MsgToDsply = DspErrorA + ' ' + Message
C MsgToDsply DSPLY
C AcceptError DSPLY
C EVAL *INLR = *ON
C RETURN
C ELSE
C EVAL SdId2 = rc
C ENDIF
C DOW ( rc > 0 )
C ELSE
C Eval rc = Close(SdId2)
C LEAVE
C ENDIF
C ENDDO
C ENDDO
C Eval rc = Close(SdId)
C EVAL *INLR = *ON
C RETURN
N
H
C D
/COPY SYSINC,$SocketsH
C *Entry PList
C Parm Request
C IF (SdId < 0 )
C MsgToDsply DSPLY
C SockError DSPLY
C RETURN
C ENDIF
C svaddrlen)
C IF (rc < 0 )
C MsgToDsply DSPLY
C ConnectError DSPLY
C RETURN
C ENDIF
C CALL 'QDCXLATE' 68
C PARM Buffer
C IF *IN68 = *OFF
C EVAL rc = Write(SdId:%ADDR(Buffer):BufferLen)
C ENDIF
C Eval rc = Close(SdId)
C RETURN