Skip to main content

[archive] Poblem with non-blocking read using C$SOCKET

  • September 25, 2007
  • 5 replies
  • 0 views

[Migrated content. Thread originally posted on 24 September 2007]

Hi,

I have been playing around with the C$SOCKET call to transfer data from a .NET program to a COBOL program. One problem I have is that I don't know the length of the data being passed. This did not seem to be a problem since the documentation seems to imply I can invoke a AGS-READ call with the length parameter set to zero and it will return the length of the data in the buffer. I can then call it again with the length set to the previous return parameter.

However I cannot get this to work and wondered if anybody had tried to do this, basically the return code of the first AGS-READ always return 0. If I used a blocking call and specify the number of bytes to read first time round the program works once the buffer has been filled with the specified number of characters.

I have embedded a snipped of code to see if anyone has any idea's.

Thanks,
Richard



       GET-REQUEST SECTION.
      *-------------------
       GET-REQ-01.
           CALL "C$SOCKET" USING AGS-CREATE-SERVER, 8765
                           GIVING SOCKET-HANDLE-1.
           IF SOCKET-HANDLE-1 = NULL
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           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
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           ADD 1 TO W-FILE-ID.
           MOVE W-FILE-NAME TO TEXT-NAME.
           OPEN OUTPUT TEXT-FILE.
           MOVE 0 TO READ-AMOUNT.
           PERFORM WITH TEST AFTER UNTIL READ-AMOUNT = -1
               CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                     DATA-FROM-CLIENT, 0
                               GIVING READ-AMOUNT
               IF READ-AMOUNT > 0
                  IF READ-AMOUNT > DATA-LENGTH
                     MOVE DATA-LENGTH TO READ-AMOUNT
                  END-IF
                  CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                        DATA-FROM-CLIENT, READ-AMOUNT
                                  GIVING READ-AMOUNT
                  MOVE DATA-FROM-CLIENT TO TEXT-RECORD
                  WRITE TEXT-RECORD
               END-IF
           END-PERFORM.
           CLOSE TEXT-FILE.

           MOVE SPACES TO DATA-TO-CLIENT.
           STRING "DATA STORED IN " DELIMITED BY SIZE
                  W-FILE-NAME DELIMITED BY SPACES
             INTO DATA-TO-CLIENT.
           CALL "C$SOCKET" USING AGS-WRITE, SOCKET-HANDLE-2,
                                 DATA-FROM-CLIENT, DATA-LENGTH
           CALL "C$SOCKET" USING AGS-CLOSE, SOCKET-HANDLE-2.
       GET-REQ-990.
           EXIT.

5 replies

[Migrated content. Thread originally posted on 24 September 2007]

Hi,

I have been playing around with the C$SOCKET call to transfer data from a .NET program to a COBOL program. One problem I have is that I don't know the length of the data being passed. This did not seem to be a problem since the documentation seems to imply I can invoke a AGS-READ call with the length parameter set to zero and it will return the length of the data in the buffer. I can then call it again with the length set to the previous return parameter.

However I cannot get this to work and wondered if anybody had tried to do this, basically the return code of the first AGS-READ always return 0. If I used a blocking call and specify the number of bytes to read first time round the program works once the buffer has been filled with the specified number of characters.

I have embedded a snipped of code to see if anyone has any idea's.

Thanks,
Richard



       GET-REQUEST SECTION.
      *-------------------
       GET-REQ-01.
           CALL "C$SOCKET" USING AGS-CREATE-SERVER, 8765
                           GIVING SOCKET-HANDLE-1.
           IF SOCKET-HANDLE-1 = NULL
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           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
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           ADD 1 TO W-FILE-ID.
           MOVE W-FILE-NAME TO TEXT-NAME.
           OPEN OUTPUT TEXT-FILE.
           MOVE 0 TO READ-AMOUNT.
           PERFORM WITH TEST AFTER UNTIL READ-AMOUNT = -1
               CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                     DATA-FROM-CLIENT, 0
                               GIVING READ-AMOUNT
               IF READ-AMOUNT > 0
                  IF READ-AMOUNT > DATA-LENGTH
                     MOVE DATA-LENGTH TO READ-AMOUNT
                  END-IF
                  CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                        DATA-FROM-CLIENT, READ-AMOUNT
                                  GIVING READ-AMOUNT
                  MOVE DATA-FROM-CLIENT TO TEXT-RECORD
                  WRITE TEXT-RECORD
               END-IF
           END-PERFORM.
           CLOSE TEXT-FILE.

           MOVE SPACES TO DATA-TO-CLIENT.
           STRING "DATA STORED IN " DELIMITED BY SIZE
                  W-FILE-NAME DELIMITED BY SPACES
             INTO DATA-TO-CLIENT.
           CALL "C$SOCKET" USING AGS-WRITE, SOCKET-HANDLE-2,
                                 DATA-FROM-CLIENT, DATA-LENGTH
           CALL "C$SOCKET" USING AGS-CLOSE, SOCKET-HANDLE-2.
       GET-REQ-990.
           EXIT.
If I were implementing this, I would have introduced a hand shake first, in which I would have the sender tell the recepient the length of the data.
The buffer mechanism is not telling you when the server is finished, it is just telling you when there is no more data.

[Migrated content. Thread originally posted on 24 September 2007]

Hi,

I have been playing around with the C$SOCKET call to transfer data from a .NET program to a COBOL program. One problem I have is that I don't know the length of the data being passed. This did not seem to be a problem since the documentation seems to imply I can invoke a AGS-READ call with the length parameter set to zero and it will return the length of the data in the buffer. I can then call it again with the length set to the previous return parameter.

However I cannot get this to work and wondered if anybody had tried to do this, basically the return code of the first AGS-READ always return 0. If I used a blocking call and specify the number of bytes to read first time round the program works once the buffer has been filled with the specified number of characters.

I have embedded a snipped of code to see if anyone has any idea's.

Thanks,
Richard



       GET-REQUEST SECTION.
      *-------------------
       GET-REQ-01.
           CALL "C$SOCKET" USING AGS-CREATE-SERVER, 8765
                           GIVING SOCKET-HANDLE-1.
           IF SOCKET-HANDLE-1 = NULL
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           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
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           ADD 1 TO W-FILE-ID.
           MOVE W-FILE-NAME TO TEXT-NAME.
           OPEN OUTPUT TEXT-FILE.
           MOVE 0 TO READ-AMOUNT.
           PERFORM WITH TEST AFTER UNTIL READ-AMOUNT = -1
               CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                     DATA-FROM-CLIENT, 0
                               GIVING READ-AMOUNT
               IF READ-AMOUNT > 0
                  IF READ-AMOUNT > DATA-LENGTH
                     MOVE DATA-LENGTH TO READ-AMOUNT
                  END-IF
                  CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                        DATA-FROM-CLIENT, READ-AMOUNT
                                  GIVING READ-AMOUNT
                  MOVE DATA-FROM-CLIENT TO TEXT-RECORD
                  WRITE TEXT-RECORD
               END-IF
           END-PERFORM.
           CLOSE TEXT-FILE.

           MOVE SPACES TO DATA-TO-CLIENT.
           STRING "DATA STORED IN " DELIMITED BY SIZE
                  W-FILE-NAME DELIMITED BY SPACES
             INTO DATA-TO-CLIENT.
           CALL "C$SOCKET" USING AGS-WRITE, SOCKET-HANDLE-2,
                                 DATA-FROM-CLIENT, DATA-LENGTH
           CALL "C$SOCKET" USING AGS-CLOSE, SOCKET-HANDLE-2.
       GET-REQ-990.
           EXIT.
If I were implementing this, I would have introduced a hand shake first, in which I would have the sender tell the recepient the length of the data.
The buffer mechanism is not telling you when the server is finished, it is just telling you when there is no more data.

[Migrated content. Thread originally posted on 24 September 2007]

Hi,

I have been playing around with the C$SOCKET call to transfer data from a .NET program to a COBOL program. One problem I have is that I don't know the length of the data being passed. This did not seem to be a problem since the documentation seems to imply I can invoke a AGS-READ call with the length parameter set to zero and it will return the length of the data in the buffer. I can then call it again with the length set to the previous return parameter.

However I cannot get this to work and wondered if anybody had tried to do this, basically the return code of the first AGS-READ always return 0. If I used a blocking call and specify the number of bytes to read first time round the program works once the buffer has been filled with the specified number of characters.

I have embedded a snipped of code to see if anyone has any idea's.

Thanks,
Richard



       GET-REQUEST SECTION.
      *-------------------
       GET-REQ-01.
           CALL "C$SOCKET" USING AGS-CREATE-SERVER, 8765
                           GIVING SOCKET-HANDLE-1.
           IF SOCKET-HANDLE-1 = NULL
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           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
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           ADD 1 TO W-FILE-ID.
           MOVE W-FILE-NAME TO TEXT-NAME.
           OPEN OUTPUT TEXT-FILE.
           MOVE 0 TO READ-AMOUNT.
           PERFORM WITH TEST AFTER UNTIL READ-AMOUNT = -1
               CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                     DATA-FROM-CLIENT, 0
                               GIVING READ-AMOUNT
               IF READ-AMOUNT > 0
                  IF READ-AMOUNT > DATA-LENGTH
                     MOVE DATA-LENGTH TO READ-AMOUNT
                  END-IF
                  CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                        DATA-FROM-CLIENT, READ-AMOUNT
                                  GIVING READ-AMOUNT
                  MOVE DATA-FROM-CLIENT TO TEXT-RECORD
                  WRITE TEXT-RECORD
               END-IF
           END-PERFORM.
           CLOSE TEXT-FILE.

           MOVE SPACES TO DATA-TO-CLIENT.
           STRING "DATA STORED IN " DELIMITED BY SIZE
                  W-FILE-NAME DELIMITED BY SPACES
             INTO DATA-TO-CLIENT.
           CALL "C$SOCKET" USING AGS-WRITE, SOCKET-HANDLE-2,
                                 DATA-FROM-CLIENT, DATA-LENGTH
           CALL "C$SOCKET" USING AGS-CLOSE, SOCKET-HANDLE-2.
       GET-REQ-990.
           EXIT.
Thanks for the tip Gisle, I have implemented it using a handshake telling the COBOL server program how much data it's going to receive and it's works fine.

[Migrated content. Thread originally posted on 24 September 2007]

Hi,

I have been playing around with the C$SOCKET call to transfer data from a .NET program to a COBOL program. One problem I have is that I don't know the length of the data being passed. This did not seem to be a problem since the documentation seems to imply I can invoke a AGS-READ call with the length parameter set to zero and it will return the length of the data in the buffer. I can then call it again with the length set to the previous return parameter.

However I cannot get this to work and wondered if anybody had tried to do this, basically the return code of the first AGS-READ always return 0. If I used a blocking call and specify the number of bytes to read first time round the program works once the buffer has been filled with the specified number of characters.

I have embedded a snipped of code to see if anyone has any idea's.

Thanks,
Richard



       GET-REQUEST SECTION.
      *-------------------
       GET-REQ-01.
           CALL "C$SOCKET" USING AGS-CREATE-SERVER, 8765
                           GIVING SOCKET-HANDLE-1.
           IF SOCKET-HANDLE-1 = NULL
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           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
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           ADD 1 TO W-FILE-ID.
           MOVE W-FILE-NAME TO TEXT-NAME.
           OPEN OUTPUT TEXT-FILE.
           MOVE 0 TO READ-AMOUNT.
           PERFORM WITH TEST AFTER UNTIL READ-AMOUNT = -1
               CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                     DATA-FROM-CLIENT, 0
                               GIVING READ-AMOUNT
               IF READ-AMOUNT > 0
                  IF READ-AMOUNT > DATA-LENGTH
                     MOVE DATA-LENGTH TO READ-AMOUNT
                  END-IF
                  CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                        DATA-FROM-CLIENT, READ-AMOUNT
                                  GIVING READ-AMOUNT
                  MOVE DATA-FROM-CLIENT TO TEXT-RECORD
                  WRITE TEXT-RECORD
               END-IF
           END-PERFORM.
           CLOSE TEXT-FILE.

           MOVE SPACES TO DATA-TO-CLIENT.
           STRING "DATA STORED IN " DELIMITED BY SIZE
                  W-FILE-NAME DELIMITED BY SPACES
             INTO DATA-TO-CLIENT.
           CALL "C$SOCKET" USING AGS-WRITE, SOCKET-HANDLE-2,
                                 DATA-FROM-CLIENT, DATA-LENGTH
           CALL "C$SOCKET" USING AGS-CLOSE, SOCKET-HANDLE-2.
       GET-REQ-990.
           EXIT.
Thanks for the tip Gisle, I have implemented it using a handshake telling the COBOL server program how much data it's going to receive and it's works fine.

[Migrated content. Thread originally posted on 24 September 2007]

Hi,

I have been playing around with the C$SOCKET call to transfer data from a .NET program to a COBOL program. One problem I have is that I don't know the length of the data being passed. This did not seem to be a problem since the documentation seems to imply I can invoke a AGS-READ call with the length parameter set to zero and it will return the length of the data in the buffer. I can then call it again with the length set to the previous return parameter.

However I cannot get this to work and wondered if anybody had tried to do this, basically the return code of the first AGS-READ always return 0. If I used a blocking call and specify the number of bytes to read first time round the program works once the buffer has been filled with the specified number of characters.

I have embedded a snipped of code to see if anyone has any idea's.

Thanks,
Richard



       GET-REQUEST SECTION.
      *-------------------
       GET-REQ-01.
           CALL "C$SOCKET" USING AGS-CREATE-SERVER, 8765
                           GIVING SOCKET-HANDLE-1.
           IF SOCKET-HANDLE-1 = NULL
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           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
               MOVE 0 TO W-RUN-SERVER
               GO TO GET-REQ-990
           END-IF.
           ADD 1 TO W-FILE-ID.
           MOVE W-FILE-NAME TO TEXT-NAME.
           OPEN OUTPUT TEXT-FILE.
           MOVE 0 TO READ-AMOUNT.
           PERFORM WITH TEST AFTER UNTIL READ-AMOUNT = -1
               CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                     DATA-FROM-CLIENT, 0
                               GIVING READ-AMOUNT
               IF READ-AMOUNT > 0
                  IF READ-AMOUNT > DATA-LENGTH
                     MOVE DATA-LENGTH TO READ-AMOUNT
                  END-IF
                  CALL "C$SOCKET" USING AGS-READ, SOCKET-HANDLE-2,
                                        DATA-FROM-CLIENT, READ-AMOUNT
                                  GIVING READ-AMOUNT
                  MOVE DATA-FROM-CLIENT TO TEXT-RECORD
                  WRITE TEXT-RECORD
               END-IF
           END-PERFORM.
           CLOSE TEXT-FILE.

           MOVE SPACES TO DATA-TO-CLIENT.
           STRING "DATA STORED IN " DELIMITED BY SIZE
                  W-FILE-NAME DELIMITED BY SPACES
             INTO DATA-TO-CLIENT.
           CALL "C$SOCKET" USING AGS-WRITE, SOCKET-HANDLE-2,
                                 DATA-FROM-CLIENT, DATA-LENGTH
           CALL "C$SOCKET" USING AGS-CLOSE, SOCKET-HANDLE-2.
       GET-REQ-990.
           EXIT.
Thanks for the tip Gisle, I have implemented it using a handshake telling the COBOL server program how much data it's going to receive and it's works fine.