error with raspberry tcp socket

stablex
2016-06-24
2018-01-29
  • stablex - 2016-06-24

    I use raspberry with tcp socket client to receive data, each message is 93030 bytes fixed. Because the TCP socket, the message are divided in small chunk. To make sure to received full message, I make in the function TcpReceiveData with while loop.
    it when well but after 20 mins or more later, receive straight error with raspberry TCP socket, see picture. after problem occurred, i login raspberry codesys, the program is in stop mode(halt).

    is there anybody can tell me where are the problem.

    // TCP client main program
    IF bInit THEN
       (*Register Callbacks                                    *)
       RegisterCallbacks();
       bInit:= FALSE;
       bActive:=TRUE;
    END_IF
    IF bActive THEN
          IF diSocket = SOCKET_INVALID THEN
          diSocket := TcpClientOpenSocket(uiPort, stDestIPAddress);
       ELSE
          bConnected:=TRUE;
          dataRecv:=FALSE;
          (*----------------------------------------------------------------------*)
          (*   Receive                           *)
          (*----------------------------------------------------------------------*)
       REPEAT
             
             diReceived:= TcpReceiveData(diSocket, PtrRecvData, LenRecvData, 100);
             IF diReceived > 0 THEN
                diReceived:=0;
                dataRecv:=TRUE;
             END_IF
             
             UNTIL    diReceived <= 0
          END_REPEAT;
          IF diReceived < 0 THEN (*Problem occured*)
             bConnected:=FALSE;
             CloseSocket(ADR(diSocket));
          END_IF
       END_IF
    END_IF
    
    //FUNCTION TcpReceiveData : DINT
    IF SocketIsReadable(diSocket, diTimeout) THEN
       WHILE ( tempRecValue < diDataSize ) DO 
          temp:= SysSockRecv(diSocket, pbyData+[b]tempRecValue[/b], diDataSize, 0);
          tempRecValue:= tempRecValue + temp;
       END_WHILE
       
       TcpReceiveData:=tempRecValue;
       
       IF TempRecvalue > 0 THEN
          TempRecvalue :=0;
       END_IF
          
       IF TcpReceiveData <= 0 THEN
          TcpReceiveData:= TcpReceiveData - 1;
       END_IF
    END_IF
    

    IMG: fault.png

     
  • danyamian - 2018-01-29

    stablex hat geschrieben:
    I use raspberry with tcp socket client to receive data, each message is 93030 bytes fixed. Because the TCP socket, the message are divided in small chunk. To make sure to received full message, I make in the function TcpReceiveData with while loop.
    it when well but after 20 mins or more later, receive straight error with raspberry TCP socket, see picture. after problem occurred, i login raspberry codesys, the program is in stop mode(halt).
    is there anybody can tell me where are the problem.

    // TCP client main program
    IF bInit THEN
       (*Register Callbacks                                    *)
       RegisterCallbacks();
       bInit:= FALSE;
       bActive:=TRUE;
    END_IF
    IF bActive THEN
          IF diSocket = SOCKET_INVALID THEN
          diSocket := TcpClientOpenSocket(uiPort, stDestIPAddress);
       ELSE
          bConnected:=TRUE;
          dataRecv:=FALSE;
          (*----------------------------------------------------------------------*)
          (*   Receive                           *)
          (*----------------------------------------------------------------------*)
       REPEAT
             
             diReceived:= TcpReceiveData(diSocket, PtrRecvData, LenRecvData, 100);
             IF diReceived > 0 THEN
                diReceived:=0;
                dataRecv:=TRUE;
             END_IF
             
             UNTIL    diReceived <= 0
          END_REPEAT;
          IF diReceived < 0 THEN (*Problem occured*)
             bConnected:=FALSE;
             CloseSocket(ADR(diSocket));
          END_IF
       END_IF
    END_IF
    
    //FUNCTION TcpReceiveData : DINT
    IF SocketIsReadable(diSocket, diTimeout) THEN
       WHILE ( tempRecValue < diDataSize ) DO 
          temp:= SysSockRecv(diSocket, pbyData+[b]tempRecValue[/b], diDataSize, 0);
          tempRecValue:= tempRecValue + temp;
       END_WHILE
       
       TcpReceiveData:=tempRecValue;
       
       IF TempRecvalue > 0 THEN
          TempRecvalue :=0;
       END_IF
          
       IF TcpReceiveData <= 0 THEN
          TcpReceiveData:= TcpReceiveData - 1;
       END_IF
    END_IF
    

    Hi, I'm working on a similar project. I have a raspberry in which I need to run a TCP server where I will receive messages from clients by sockets. I can not get it to work properly, have you managed to get it to work properly? Do you have more information on the server?

    Thank you very much.

     

Log in to post a comment.