Hi All,

I have an application where in i shall have A vxWorks Target acting as
TCP Server ( Data Receiver) and Windows PC acting as TCP Client
(Sending Data). For your convinence purpose, consider it to be the
standard Blastee & Blaster programs respectively.

This program when tested with a target ( Consider PcPentium for
example) running vxWorks5.5.

Server: sp blastee,5050,1000,16000
where 5050 is the port no.
1000 receive buffer length
16000 maximum buffer length

Client: winBlaster 5050 14 16000
where is the target IP Address
5050 is the port no.
14 Send buffer length
16000 maximum buffer length

The receiver would receive 14 bytes of data for every packet.

The same program when tested with a target running vxWorks 6.2, the
receiver receive muliples of 14 bytes of data for every packet. If i
delay the Client (Data Sender) by 100 ms, then the receiver would
receive 14 bytes of data for every packet.

My question to all is:
1. Why there is a difference in the way the program behaves in case of
vxWorks 5.5 & vxWorks6.x

2. What is the role played by the delay in case of vxWorks 6.2.

I am also pasting the source code of both vxWorks_Blastee program &
Windows_Blaster programs for your convinence. Please compile it and run
it individually on a Tornado2.2 & Workbench2.2 installations and test
it.

---------------------------------- VxWorks Blastee Program starts
here--------------------------------------------
/* vxBlastee.c - reads given size message from the client*/

/* Copyright 1984-1997 Wind River Systems, Inc. */

/*
modification history
--------------------
01f,06nov97,mm added copyright.
01e,10Oct97,mm cast arg 4 of function setsockopt
01d,10Oct97,mm added arguments to file logMsg
01c,29Sep97,mm cast arg 1 of `bzero'
01b,16Sep97,mm added include , , ,
,
, ,
01a,29jan94,ms cleaned up for VxDemo.
*/

#include
#include
#include
#include
#include
#include
#include
#include
#include "wdLib.h"
#include "in.h"
#include "ioLib.h"

LOCAL int blastNum;
LOCAL int wdIntvl = 60;

LOCAL WDOG_ID blastWd = NULL;
int blasteeStop;
LOCAL void blastRate ();
int countpack=0;

/************************************************** ***************************
* blastee - server task for VxWorks target
*
* DESCRIPTION
*
* This is a server program which communicates with client through
a
* TCP socket. It allows to configure the maximum size of
socket-level
* receive buffer. It repeatedly reads a given size message from
the client
* and reports the number of bytes read every minute. It stops
receiving
* the message when the global variable blasteeStop is set to 1.
*
* EXAMPLE:
*
* To run this blastee task from the VxWorks shell do as follows:
* -> sp (blastee, 7000, 1000, 16000)
*
* To stop blastee task from the VxWorks shell do as follows:
* -> blasteeStop = 1
*
*/


void blastee
(
int port, /* the port number to read from */
int size, /* size of the meesage */
int blen /* maximum size of socket-level receive buffer */
)
{
struct sockaddr_in serverAddr; /* server's address */
struct sockaddr_in clientAddr; /* client's address */
char *buffer;
int sock;
int snew;
int len;

buffer = (char *) malloc (size);

if (buffer == NULL)
{
perror ("cannot allocate buffer of size ");
exit (1);
}

/* Create watchdog timer */
if (blastWd == NULL && (blastWd = wdCreate ()) == NULL)
{
perror ("cannot create blast watchdog");
free (buffer);
exit (1);
}

/* Start watchdog after a minute*/
wdStart (blastWd, sysClkRateGet () * wdIntvl, (FUNCPTR) blastRate,
0);

/* Zero out the sock_addr structures.
* This MUST be done before the socket calls.
*/
bzero ((char *) &serverAddr, sizeof (serverAddr));
bzero ((char *) &clientAddr, sizeof (clientAddr));

/* Open the socket. Use ARPA Internet address format and stream
sockets. */
sock = socket (AF_INET, SOCK_STREAM, 0);

if (sock < 0)
{
perror ("cannot open socket");
free (buffer);
exit (1);
}

/* Set up our internet address, and bind it so the client can
connect. */
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons (port);

if (bind (sock, (struct sockaddr *)&serverAddr, sizeof
(serverAddr)) < 0)
{
perror ("bind error");
free (buffer);
exit (1);
}

/* Listen, for the client to connect to us. */
if (listen (sock, 2) < 0)
{
perror ("listen failed");
free (buffer);
exit (1);
}

len = sizeof (clientAddr);

snew = accept (sock, (struct sockaddr *) &clientAddr, &len);
if (snew == ERROR)
{
printf ("accept failed");
close (sock);
exit (1);
}

blastNum = 0;

/* maximum size of socket-level receive buffer */
if (setsockopt (snew, SOL_SOCKET, SO_RCVBUF,(char *) &blen, sizeof
(blen)) < 0)
{
perror ("setsockopt SO_SNDBUF failed");
free (buffer);
exit (1);
}

blasteeStop = FALSE;


for (;
{
int numRead;

if (blasteeStop == TRUE)
break;

if ((numRead = read (snew, buffer, size)) < 0)
{
perror ("blastee read error");
break;
}
printf("%d %d\n",countpack++,numRead);
blastNum += numRead;
}


wdCancel (blastWd);

close (sock);
close (snew);

free (buffer);
printf ("blastee end.\n");
}

/************************************************** ***************************
* blastRate - watchdog routine executed every one minute to report
number of
* bytes read
*
*/

LOCAL void blastRate ()
{
if (blastNum > 0)
{
logMsg ("%d bytes/sec\n", blastNum / wdIntvl,0, 0, 0, 0, 0);
blastNum = 0;
}
else
{
logMsg ("No bytes read in the last 60 seconds.\n",0, 0, 0, 0, 0, 0);
}
wdStart (blastWd, sysClkRateGet () * wdIntvl, (FUNCPTR) blastRate,
0);
}
---------------------------------- VxWorks Blastee Program Ends
here--------------------------------------------

---------------------------------- WinBlaster Program starts
here--------------------------------------------
/* winBlaster.c - blasts another system with the given message size */

/* Copyright 1984-1997 Wind River Systems, Inc. */

/*
01a,29jan94,ms cleaned up for VxDemo.
*/

/************************************************** ***************************
* blaster - client program for MS WINDOWS host
*
* DESCRIPTION
*
* This is a client program which connects to the server via TCP
socket.
* It allows to configure the maximum size of the socket-level
* send buffer. It repeatedly sends a given size message to the
given port
* at destination target.
*
* EXAMPLE:
*
* To run this blaster program from your WINDOWS host do the
following at
* a DOS prompt:
* C:\> blaster 7000 1000 16000
*
*
*/


#include
#include /* */
#include
#include
#include



int main
(
int argc,
char ** argv
)
{
struct sockaddr_in sin;
int sock;
int ix = 0;
char *buffer;
int blen; /* maximum size of socket-level send buffer */
int size; /* size of the message to be sent */
struct hostent *hp;

WORD wVersionRequested;
WSADATA wsaData;
int err;
int flag = 1;
/* initialize winsock.dll */
wVersionRequested = MAKEWORD(1, 1);
err = WSAStartup(wVersionRequested, &wsaData);

if (err != 0)
/* Tell the user that we couldn't find a useable */
/* winsock.dll. */

return;

/* Confirm that the Windows Sockets DLL supports 1.1.*/
/* Note that if the DLL supports versions greater */
/* than 1.1 in addition to 1.1, it will still return */
/* 1.1 in wVersion since that is the version we */
/* requested. */

if ( LOBYTE( wsaData.wVersion ) != 1 ||
HIBYTE( wsaData.wVersion ) != 1 )
{
/* Tell the user that we couldn't find a useable */
/* winsock.dll. */

perror ("Unable to initialize WinSock Version 1.1\n");
WSACleanup();
return;
}

/* The Windows Sockets DLL is acceptable. Proceed. */


if (argc < 5)
{
printf ("usage: %s targetname port size bufLen\n", argv [0]);
exit (1);
}

memset(&sin, 0, sizeof(sin));

/* Create a TCP socket */

sock = socket (PF_INET, SOCK_STREAM, 0);

if (sock < 0)
{
perror ("cannot open socket");
exit (1);
}

hp = gethostbyname (argv[1]);
if (hp == 0 && (sin.sin_addr.s_addr = inet_addr (argv [1])) == -1)
{
fprintf (stderr, "%s: unkown host\n", argv [1]);
exit (2);
}

/* Fill in the hostent structure */

if (hp != 0)
memcpy (&sin.sin_addr, hp->h_addr, hp->h_length);

sin.sin_family = PF_INET;
sin.sin_port = htons ((short) atoi (argv [2]));
size = atoi (argv [3]);
blen = atoi (argv [4]);

if ((buffer = (char *) malloc (size)) == NULL)
{
perror ("cannot allocate buffer of size ");
exit (1);
}

/* Set the size of the socket send and receive buffers to blen */

if (setsockopt (sock, SOL_SOCKET, SO_SNDBUF,
(char *) &blen, sizeof (blen)) < 0)
{
perror ("setsockopt SO_SNDBUF failed");
exit (1);
}
/*{
int result = setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,(char *)
&flag,sizeof(flag));
}*/


if (setsockopt (sock, SOL_SOCKET, SO_RCVBUF,
(char*) &blen, sizeof (blen)) < 0)
{
perror ("setsockopt SO_RCVBUF failed");
exit (1);
}
/**/
/* if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)
&blen,sizeof(int)) == ERROR)
{
perror("setsockopt: tcp_nodelay");
close(sock);
return (ERROR);
}*/

/**/
/* Connect to the server */

if (connect (sock, (SOCKADDR *) &sin, sizeof (sin)) < 0)
{
perror ("connect");
printf ("connect failed: host %s port %d\n", inet_ntoa
(sin.sin_addr),
ntohs (sin.sin_port));
exit (1);
}

/* Send a data buffer of length size to the server repeatedly */
for (;
{
int y;
if ((y = send(sock, buffer, size, 0)) < 0)
{
perror ("blaster write error");
break;
}
Sleep(1);
}

close (sock);

free (buffer);
printf ("blaster exit.\n");
}

---------------------------------- WinBlaster Program Ends
here--------------------------------------------

Thanks in advance,

Kiran
mail to: kiran81077@gmail.com