sponsored links



No announcement yet.

Socket Programming: recv limitation, Win32 exe limitation or Something

  • Filter
  • Time
  • Show
Clear All
new posts

  • Socket Programming: recv limitation, Win32 exe limitation or Something

    I'm attempting to interact with a Win32 service/program via an RPG program using sockets. I found something a little strange that I cannot seem to resolve. If I define the receive buffer as anything longer than char(4343), I get an ECONNRESET error.

    dcl-s senddata char(4345);    
    dcl-s recvdata like(senddata);
    // QTCPEBC translates from ascii to ebcdic              
    // QTCPASC translates from ebcdic to ascii              
    // send request through socket                          
    rc = send( s : %addr( senddata ) : %len(senddata) : 0 );
    rc = recv( s : %addr( recvdata ) : %len(recvdata) : 0 );
    if rc <= 0;                                             
      msg = %str(strerror(errno));                          
    The response will contain a raw text message followed immediately by xml. The raw text message contains the length of the response. My problem is, if I change senddata to char(4343), and the recv() is successful, the response "can" come back with a length greater than 4343. Any thoughts?

  • #2
    As a side note, I do see where it is required to put recv() in a loop until the return code is less than 1. That does work (to an extent), but I'm curious why I cannot recv() more than 4343 characters at one time.


    • #3
      ECONNRESET means you have some sort of protocol error. Hard to say what that is from what you've posted.

      I can tell you that recv() doesn't fail with buffers larger than 4343 in the general sense. I use buffers larger (sometimes much, much larger) than that all the time without problems.

      I don't see what this has to do with win32


      • TheZenbudda
        TheZenbudda commented
        Editing a comment
        I provided more information below. Not sure if there are other things I can research (besides google) to resolve this issue. Some of my requests will be larger than char(4343)

    • #4
      Scott (or anyone who knows)

      I get this error very consistently if my buffer length goes beyond a certain limit. I am not sure how to research it any further. Here is a sample program that follows the exact flow of what i'm doing.

      PHP Code:
      dcl-s senddata char(32704);    
      dcl-s recvdata like(senddata); 
      dcl-s mydata like(senddata);

      /include mylib/qcpylesrc,errno_h  

      // define the socket information        
      addrlen = %size(sockaddr);              
      p_connto = %alloc(addrlen);             
      p_sockaddr p_connto;                  
      sin_family AF_INET;                   
      sin_addr inet_addr('xxx.xxx.xxx.xxx');   
      sin_port 1000;                        
      sin_zero = *allx'00';                   

      mySocket socket(AF_INET:SOCK_STREAM:IPPROTO_IP);
      rc connectmySocket p_connto addrlen ); 

      senddata 'blah blah blah valid xml';
      rc sendmySocket : %addrsenddata ) : %len(senddata) : ); 

      sleep(1); // give data time to be send before receiving
      rc recvmySocket : %addrrecvdata ) : %len(recvdata) : ); 

      rc 1;
      // error

      dou rc 1;
      myData recvData;
      rc recvmySocket : %addrrecvdata ) : %len(recvdata) : ); 

      rc close(mySocket); 



      • TheZenbudda
        TheZenbudda commented
        Editing a comment
        (since i cannot edit my post, i'm adding more info here)

        What is the rpg equivalent of the php socket_create(AF_INET, SOCK_STREAM, SOL_TCP); ? It would "seem" that I'm using that.

    • #5
      It doesn't look like you're working with any protocol that I'm familiar with. Maybe this is some custom protocol you've designed? You just write all of your data, and then read data back from a TCP socket? How would the remote side know when to stop receiving? Never seen anything written like this.

      There's nothing in what you've posted that makes it clear why you'd be getting an ECONNRESET. You should talk to whomever writes the application you're communicating with and ask them under what circumstances they'd send a 'reset'.


      • #6

        Thanks for your response. I'm not sure what you mean by "custom protocol". Maybe i'm taking you too literally? I copied and pasted the socket(AF_INET:SOCK_STREAM:IPPROTO_IP) definition from your socket programming guide (where the protocol is defined). In case you didn't mean the communication protocol, that code I posted above is acting as a client that communicates with a Win32 executable (the host) to get data back. I will be reaching out to the 3rd party to figure out why we would get this failure when the response buffer is larger than char(4343).


        • #7
          (Cannot edit my previous post so added to it here). The data in the buffer has a <start> and <stop> tag to let the host know the client is done sending. Is that what you were referring to?


          • #8
            I meant the application-level protocol.

            Obviously you're running TCP.