Application messages and tcp, Partial reads, Application messages and tcp partial reads – Rockwell Automation 1768-EWEB EtherNet/IP Web Server Module User Manual User Manual

Page 137

Advertising
background image

Publication ENET-UM527E-EN-P - October 2006

Socket Interface 137

Application Messages and TCP

A TCP connection is a byte stream between two application entities.
The application protocol determines the message formats. Messages
can be fixed size or variable size.

If an application sends variable size messages, a common strategy is
to first send a fixed size ’header’ containing the size of the message,
followed by the message. The receiving device can first issue a Read
of the fixed size header to determine the remaining size, and then
issue a subsequent Read to receive the remaining data.

Partial Reads

It is possible for a Read service to return a BufLen that is less that the
requested amount of data. For example, your program may request
100 bytes of data. Because TCP is a byte stream and not a datagram
protocol, you can receive less than 100 bytes when the Read service
returns.

Depending on the application protocol, issue additional Read requests
to receive all the data. If the application protocol dictates that all
messages are 100 bytes, then you must issue additional Reads until
you receive 100 bytes. If the application protocol uses variable size
messages, your program needs additional logic to handle variable
message sizes as defined by the application protocol.

When issuing multiple Read services, be careful to adjust the
destination tag that receives the data so that data is not overwritten.
This fragment of Structured Text logic shows an example of handling
a partial Read service.

/* copy the message we just read */

COP ( ReadResponse.Buf[0], ReadBuf[CurrentLen], ReadResponse.BufLen );

CurrentLen := CurrentLen + ReadResponse.BufLen;

/* do we need to read more data get a complete message? */

if ( CurrentLen < ApplicationMsgLen ) then

/* issue another read */

ReadParams.BufLen := ApplicationMsgLen - CurrentLen;

MSG ( ReadMSG0 );

end_if;

Advertising
This manual is related to the following products: