Highlighted
Absent Member.
Absent Member.
1913 views

Creating a Server Socket in AcuCOBOL

[Migrated content. Thread originally posted on 18 February 2011]

Hi All,

I tried to create a Server Socket in AcuCOBOL GT extend 6 using C$SOCKET. It is accepting connection from a Java Client but it is not reading data from it.

Please help if any one have sample source..

Thanks,
Mano
0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Creating a Server Socket in AcuCOBOL

You may need to update from version 6 to a supported version - this is the example that is sent with the latest version:

IDENTIFICATION DIVISION.
PROGRAM-ID. SOCKSRV1.

* Copyright (c) 1989-2010 by Micro Focus
* Users of ACUCOBOL-GT may freely use this file.

* This program demonstrates a single-client server.
* A single client can connect to this server, and
* when the client disconnects, the server shuts down.

DATA DIVISION.
WORKING-STORAGE SECTION.
COPY "def/socket.def".

78 DATA-LENGTH VALUE 50.
77 SOCKET-HANDLE-1 USAGE HANDLE.
77 SOCKET-HANDLE-2 USAGE HANDLE.
77 DATA-FROM-CLIENT PIC X(DATA-LENGTH).
77 READ-AMOUNT PIC S99.

PROCEDURE DIVISION.
MAIN-PGH.
DISPLAY WINDOW ERASE.
DISPLAY "Creating server socket: " LINE 5 COL 5.
CALL "C$SOCKET" USING AGS-CREATE-SERVER, 8765
GIVING SOCKET-HANDLE-1.
DISPLAY SOCKET-HANDLE-1 CONVERT.
IF SOCKET-HANDLE-1 = NULL
STOP RUN
END-IF.

DISPLAY "Accepting connection from client: " LINE 6 COL 5.
CALL "C$SOCKET" USING AGS-ACCEPT, SOCKET-HANDLE-1
GIVING SOCKET-HANDLE-2.
CALL "C$SOCKET" USING AGS-CLOSE, SOCKET-HANDLE-1.
DISPLAY SOCKET-HANDLE-2 CONVERT.
IF SOCKET-HANDLE-2 = NULL
STOP RUN
END-IF.

PERFORM WITH TEST AFTER UNTIL READ-AMOUNT = -1
DISPLAY "Reading client data" LINE 7 COL 5
CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
DATA-FROM-CLIENT, DATA-LENGTH
GIVING READ-AMOUNT
IF READ-AMOUNT = DATA-LENGTH
DISPLAY DATA-FROM-CLIENT LINE 8 COL 5

INSPECT DATA-FROM-CLIENT CONVERTING
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO
"abcdefghijklmnopqrstuvwxyz"

DISPLAY "Writing lower case text to client"
LINE 9 COL 5
CALL "C$SOCKET" USING AGS-WRITE, SOCKET-HANDLE-2,
DATA-FROM-CLIENT, DATA-LENGTH
END-IF
END-PERFORM.
CALL "C$SOCKET" USING AGS-CLOSE, SOCKET-HANDLE-2.
STOP RUN.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.