skip to main content

Library Routines : C$SOCKET

C$SOCKET
The C$SOCKET library routine provides a number of functions to manage sockets.
Syntax:
 CALL "C$SOCKET" USING opCode 
Parameters:
Note: Acucobol-GT op-codes names having the prefix "AGS-" instead of "CSOCKET-" are supported for compatibility.
Return code:
returnCode can be any signed numeric data item. The meaning depends on the opcode.
Examples:
Example - Socket server program to listen messages from different clients and respond to them
       program-id. sockserver.
       working-storage section.
       copy "issocket.def".
       78  data-len        value 1024.
       77  sock-hnd-1      usage handle.
       77  sock-hnd-2      usage handle.
       77  client-data     pic x(data-len).
       77  bytes-read      pic s9999.
       77  sock-timeout    signed-int value -1.
       77  sock-thread     pic 9(4).
       procedure division chaining sock-thread.
           call "c$socket" using csocket-create-server, sock-thread
           if sock-hnd-1 = null
              perform exit-program
           perform until client-data(1:9) = "sockclose"
               call "c$socket" using csocket-next-read, sock-hnd-1,
               move sock-hnd-2 to return-code
               if return-code = -1
                   call "c$socket" using csocket-close, sock-hnd-1
               if return-code = 0
               if sock-hnd-2 = sock-hnd-1
                   call "c$socket" using csocket-accept, sock-hnd-1
               call "c$socket" using csocket-read, sock-hnd-2,
               if bytes-read = data-len
                   if client-data(1:9not = "sockclose"
                       call "c$socket" using csocket-close, sock-hnd-2
                       move "01 Resend data" to client-data
                       call "c$socket" using csocket-write, sock-hnd-2,
           perform exit-program.
            move "00 data ok" to client-data
            call "c$socket" using csocket-write, sock-hnd-2,

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left