Issues with Socket Interface Object (07h)

Hello to all!
For two weeks I have been trying to create a communication with the Socket Interface Object (07h) in Server mode but unsuccessfully!! :sob: :sob: :sob:
In my state machine I do:

  1. create socket → OK
  2. bind socket → OK
  3. listen socket → OK
  4. accept socket —> NOT OK
    … and then I cannot continue
    I use a Client PC program like (Hercules.exe) but when I try to connect with socket I can’t receive any response
    Can you help me?

Only for clarify my problem I add my “C” software routine
;----------------------------
State Machine
;----------------------------
switch (StatusSocket)
{
case 0:
if (StartSocketTimer==0)
{
app_socket_done=0;
StatusSocket++;
}
break;
case 1:
ABCC_AddCmdSeq( anb_asSocket, CbfSocketDone );
if (app_socket_done)
{
app_socket_done=0;
StatusSocket++;
}
break;
case 2:
ABCC_AddCmdSeq( anb_asSocketBind, CbfSocketDone );
if (app_socket_done)
{
app_socket_done=0;
StatusSocket++;
}
break;
case 3:
ABCC_AddCmdSeq( anb_asSocketListen, CbfSocketDone );
if (app_socket_done)
{
app_socket_done=0;
StartSocketTimer=5;
StatusSocket++;
}
break;
case 4:
if (StartSocketTimer==0)
{
ABCC_AddCmdSeq( anb_asSocketAccept, NULL );
StatusSocket++;
}
break;
case 5:
if (AcceptOK)
{
AcceptOK=0;
StatusSocket=10;
}
else if (anb_bSendSocketError==6)
{
Nop();
Nop();
StartSocketTimer=5;
StatusSocket–;
}
else
{
Nop();
}
break;
etc…
.
.
.


/*------------------------------------------------------------------------------
** Creates an Socket.
**------------------------------------------------------------------------------
** Arguments:
** psMsg - Message to send to ABCC.
**
** Returns:
** ABCC_CmdSeqCmdStatusType - Response for command callback.
**------------------------------------------------------------------------------
/
static ABCC_CmdSeqCmdStatusType CreateSocketCmd( ABP_MsgType
psMsg )
{
ABCC_SetMsgHeader( psMsg,
ABP_OBJ_NUM_SOC,
0,
0, // 00h SOCK_STREAM, NON-BLOCKING (TCP)
3, // 03h CREATE
0,
ABCC_GetNewSourceId() );

return( ABCC_SEND_COMMAND );
}
/*------------------------------------------------------------------------------
** Processes a response to a CreateSocketCmd. Reads in and stores the new
** Socket instance number that was generated by the CreateSocketCmd.
**------------------------------------------------------------------------------
** Arguments:
** psMsg - Message received from the ABCC.
**
** Returns:
** ABCC_CmdSeqCmdStatusType - Response for command callback.
*------------------------------------------------------------------------------
/
static ABCC_CmdSeqRespStatusType HandleCreateSocketRsp( ABP_MsgType
psMsg )
{
if( ABCC_VerifyMessage( psMsg ) == ABCC_EC_NO_ERROR )
{
/

** Successfully created a socket
** Store the created socket
*/
ABCC_GetMsgData16( psMsg, &anb_socket_Instance, 0 );

  return( ABCC_EXEC_NEXT_COMMAND );

}

/*
** Something went wrong
/
return( ABCC_RESP_ABORT_SEQ );
}
/
------------------------------------------------------------------------------
** Builds the command for setting the Bind Socket.
**
** This function is a part of a command sequence.
**------------------------------------------------------------------------------
/
static ABCC_CmdSeqCmdStatusType BindSocketCmd( ABP_MsgType
psMsg )
{

  ABCC_SetMsgHeader( psMsg,
                     ABP_OBJ_NUM_SOC,
                     anb_socket_Instance,
                     0, 	// Port number
                     16,	// 10h BIND
                     0,
                     ABCC_GetNewSourceId() );

  return( ABCC_SEND_COMMAND );

}
/*------------------------------------------------------------------------------
** Processes a response to a BindSocketCmd. Reads in and stores the Port number
**
**------------------------------------------------------------------------------
** Arguments:
** psMsg - Message received from the ABCC.
**
** Returns:
** ABCC_CmdSeqCmdStatusType - Response for command callback.
*------------------------------------------------------------------------------
/
static ABCC_CmdSeqRespStatusType HandleBindSocketRsp( ABP_MsgType
psMsg )
{
if( ABCC_VerifyMessage( psMsg ) == ABCC_EC_NO_ERROR )
{
/

** Successfully port binded
** Store the port
*/
anb_socket_port=ABCC_GetMsgCmdExt( psMsg );
SocketPort= anb_socket_port;
return( ABCC_EXEC_NEXT_COMMAND );
}

/*
** Something went wrong
*/
return( ABCC_RESP_ABORT_SEQ );
}

/*------------------------------------------------------------------------------
** Builds the command for setting the Socket listen.
**
** This function is a part of a command sequence.
**------------------------------------------------------------------------------
/
static ABCC_CmdSeqCmdStatusType ListenSocketCmd( ABP_MsgType
psMsg )
{

  ABCC_SetMsgHeader( psMsg,
                     ABP_OBJ_NUM_SOC,
                     anb_socket_Instance,
                     0, 	// 
                     18,	// 12h LISTEN
                     0,
                     ABCC_GetNewSourceId() );

  return( ABCC_SEND_COMMAND );

}
/*------------------------------------------------------------------------------
** Processes a response to a ListenSocketCmd.
**------------------------------------------------------------------------------
** Arguments:
** psMsg - Message received from the ABCC.
**
** Returns:
** ABCC_CmdSeqCmdStatusType - Response for command callback.
*------------------------------------------------------------------------------
/
static ABCC_CmdSeqRespStatusType HandleListenSocketRsp( ABP_MsgType
psMsg )
{
if( ABCC_VerifyMessage( psMsg ) == ABCC_EC_NO_ERROR )
{
/

** Successfully port listen
**
*/
return( ABCC_EXEC_NEXT_COMMAND );
}

/*
** Something went wrong
*/
//return( ABCC_RESP_ABORT_SEQ );
return( ABCC_RESP_EWOULDBLOCK );
}

/*------------------------------------------------------------------------------
** Builds the command for setting the Accept Socket.
**------------------------------------------------------------------------------
/
static ABCC_CmdSeqCmdStatusType AcceptSocketCmd( ABP_MsgType
psMsg )
{

  ABCC_SetMsgHeader( psMsg,
                     ABP_OBJ_NUM_SOC,
                     anb_socket_Instance,     //
                     0, 
                     19,	// 13h ACCEPT
                     0,
                     ABCC_GetNewSourceId() );
  SocketSourceID=ABCC_GetMsgSourceId( psMsg );
  return( ABCC_SEND_COMMAND );

}
/*------------------------------------------------------------------------------
** Processes a response to a AcceptSocketCmd. Reads in and stores the
** new Istance, IP number, Port number
**------------------------------------------------------------------------------
** Arguments:
** psMsg - Message received from the ABCC.
**
** Returns:
** ABCC_CmdSeqCmdStatusType - Response for command callback.
*------------------------------------------------------------------------------
/
static ABCC_CmdSeqRespStatusType HandleAcceptSocketRsp( ABP_MsgType
psMsg )
{
if( ABCC_VerifyMessage( psMsg ) == ABCC_EC_NO_ERROR )
{
/

** Successfully port Accept
**
*/
ABCC_GetMsgData16( psMsg, &anb_newsocket_Instance, 0 );
ABCC_GetMsgData8( psMsg, &anb_socket_IP_Byte4, 2);
ABCC_GetMsgData8( psMsg, &anb_socket_IP_Byte3, 3);
ABCC_GetMsgData8( psMsg, &anb_socket_IP_Byte2, 4);
ABCC_GetMsgData8( psMsg, &anb_socket_IP_Byte1, 5);
ABCC_GetMsgData16( psMsg, &anb_newsocket_port, 6 );
AcceptOK= 1;
return( ABCC_EXEC_NEXT_COMMAND );
}

/*
** Something went wrong
*/
anb_bSendSocketError = ABCC_GetErrorCode2( psMsg );
return( ABCC_RESP_ABORT_SEQ );
}

Thank’s in advance who can help me :blush: :blush: :blush: :blush:

Hello @paolo ,

I would recommend opening a case on mysupport.hms.se for an issue like this.

A few suggestions that could help would be to look at a network capture and see if there are any messages exchanged and check for any error responses.

Deryck

Hello Deryck,
In other post I have this answer by Tim


Do it possible to have this manual?
My problem is that I do not receive anything when I send the “ACCEPT” command
and I would like to know where I’m in wrong, if the error is in the previous command or in the last command.

Hello @paolo,

Can you share a link to that post?

Deryck

The post is in the Embedded Anybus forum, few post before mine!

Hello I haven’t been able to track down the document posted but here are two flow charts regarding the socket connections that might help.

The server in this example opens a port for incoming TCP connections.
As soon as data is incoming it will be temporarily stored and sent back (data mirroring).

The client opens the first available port (starting with 1024) and connects to it.
When connecting to a remote machine, the socket will wait until either the remote machine has responded or the telegram has timed out.
As soon as the connection is established, the client will send data and expects to receive data as answer. After receiving the response it will send data again and so on.

image
image

Many thanks Deryck, but I have already this flow charts. I’m trying to create a Server but my problem is that I cannot exexute sucessfully the “Accept” command. With my client (hercules.exe) I do not never be a le to connect.

Finally I fond the problem!
Between two consecutive command it’s necessary insert a delay (for me 200 ms).
… Create
… delay
… Bind
… delay
… Listen
… delay

Now the accept command is OK.

Thanks for following up! I did not know we needed a delay.

Deryck

Me too, but if I not wait between two command the communication don’t work for me (in my case I sent consecutive command after 5 msec)

Hello, sorry but now I have another problem.
… Create → OK
… delay
… Bind → OK
… delay
… Listen → OK
… delay
… Accept -->OK

… Read → OK (Server receive data from client)
… Send → NOT OK (Server send data to client - Loop back) and I receive always this error “ESHUTDOWN (0x0F) Socket has already been shutdown” :disappointed_relieved: :cry: :sob:
Paolo

I recommend opening a case on mysupport.hms.se We are not very familiar with the socket connection here on the forum.

Thank’s Deryck, I have already open a case for the moment without solution.
At the same time I was hoping that in the forum there was someone who had the same problem as me. :fearful: :cold_sweat: :disappointed_relieved: :cry: :sob:

Finally it work!! :grinning: :innocent: :partying_face: :sunglasses:
The problem is in SEND Command: thera are two bit that must be set also if we do not use
“Message Segmentation”

static ABCC_CmdSeqCmdStatusType SendDataSocketCmd( ABP_MsgType* psMsg )
{
anb_socket_send[0]=anb_socket_receive[0]; // Echoed data
anb_socket_send[1]=anb_socket_receive[1];
anb_socket_send[2]=anb_socket_receive[2];
anb_socket_send[3]=anb_socket_receive[3];
anb_socket_send[4]=anb_socket_receive[4];
anb_socket_send[5]=anb_socket_receive[5];
anb_socket_send[6]=’ ‘;
anb_socket_send[7]=’ ‘;
anb_socket_send[8]=’ ‘;
anb_socket_send[9]=’ ‘;
anb_socket_send[10]=’ ‘;
anb_socket_send[11]=’ ‘;
anb_socket_send[12]=’ ‘;
anb_socket_send[13]=’ ‘;
anb_socket_send[14]=’ ‘;
anb_socket_send[15]=’ ‘;
anb_socket_send[16]=’ ‘;
anb_socket_send[17]=’ ‘;
anb_socket_send[18]=’ ‘;
anb_socket_send[19]=’ ';
ABCC_SetMsgHeader( psMsg,
ABP_OBJ_NUM_SOC,
anb_newsocket_Instance,
0,
SOCK_CMD_SEND,
20,
ABCC_GetNewSourceId() );
ABCC_SetMsgCmdExt1( psMsg, 3 ); // FS=1 LS=1 (This two bit are to be set)
ABCC_SetMsgString( psMsg, &anb_socket_send[0], 20, 0 );
return( ABCC_SEND_COMMAND );
}

2 Likes