identification division.
program-id.p7.
*
data division.
working-storage section.
01  host    pic x(32) value "localhost".
01  port    pic s9(9) comp value 12345.
01  xsd     pic s9(9) comp.
01  outmsg  pic x(100).
01  inmsg   pic x(10000).
01  msglen  pic s9(9) comp.
01  n       pic s9(9) comp.
*
procedure division.
main-paragraph.
* open connection
    call "VMS_SOCKET_OPEN"
        using
            by descriptor host
            by reference port
        giving
            xsd
    end-call
* send message
    move "Hi from Cobol!" to outmsg
    call "VMS_SOCKET_SEND"
        using
           by reference xsd
           by descriptor outmsg
    end-call
* receive all messages
    move 1 to n
    perform until n = 0
        call "VMS_SOCKET_RECV"
            using
               by reference xsd
               by descriptor inmsg
               by reference msglen
           giving
               n
        end-call
        if n > 0 then
            display "|" inmsg(1:msglen) "|"
        end-if
    end-perform
* close connection
    call "VMS_SOCKET_CLOSE"
        using
            by reference xsd
    end-call
    stop run.
