EMBEDDED APPLICATIONS FCT
2.6
TCP Example Script {TCP_transfer.sc}
A simple example of a TCP data transfer script is listed
below. The script creates a TCP socket, connects to a
remote site and then sits in a receive loop until a ‘$’
character is received, after which it closes the socket and
exits.
int Err;
int PORTNUM = 3000;
int IPADDRESS = 0x0A8402A3; /* 10.132.2.163 */
int RXTX_SIZE = 1000;
char RxTxBuf[RXTX_SIZE] = “Starting! “;
char Complete = FALSE;
int APPS_IP_ERROR_TRIGGER = 36;
int APPS_IP_ERROR_STATUSBYTE = 13;
int APPS_IP_DATA_RECVD = 13;
int APPS_IP_TCPSTATUS_BYTE = 14;
int TCP_NOT_CONNECTED = 1;
int TCP_CONNECTING = 2;
int TCP_CONNECTED = 3;
/* Reset the IP error flag by reading it */
gtf( APPS_IP_ERROR_TRIGGER );
Err = pdpa( 1, 1 );
prtf( "\n PDP activate result = %d\n", Err );
if ( Err == 0 )
{
Val = ipi( 0 );
prtf( " IP Address = %x", Val );
Val = ipi( 1 );
prtf( "\n DNS 1 = %x", Val );
Val = ipi( 2 );
prtf( "\n DNS 2 = %x\n", Val );
}
else
{
prtf( "\n PDP activation failed!\n" );
return;
}
Err = ipo( 1, &SckNum );
if( Err != 0 )
{
prtf( “ \n TCP Socket open failed!\n” );
}
else
{
prtf( "\n TCP Socket Opened!\n" );
Err = tcpc( SckNum, Port, Address );
if( (Err == 0) || (Err == TCP_CONNECTING) || (Err == TCP_CONNECTED) )
{
while( !Complete && (gtb( APPS_IP_ERROR_STATUSBYTE ) == 0) )
{
int len;
/* Receive some data */
if( gtf( APPS_IP_DATA_RECVD ) )
{
prtf( "\n IP DATA RECVD" );
LZT 123 8019 R1A
12