next up previous contents
Next: I’m trying to run Up: Making Clients Previous: How do I set   Contents

My clients can not get newest visual information, because a couple of messages from the server are on the queue of the socket. How do clients get the newest message from the queue?

Here is a sample of C/C++ code that clean up queue and get the newest ``see'' information. If there are multiple ``see'' messages on the socket, this code prints the old ones, but skips them. This makes sure all hear messages are received, though.

if(FD_ISSET(sock.socketfd, &readfds)){

/*n = receive_message(buf, MAXMESG, sock, &port) ; */

/*keep receiving messages until the socket is empty*/

while((n = receive_message(tmp, MAXMESG, sock, &port)) > 0)int copy = TRUE; /* in general, copy tmp to buf */

if (MessageCounter > 0) /* not first time through while */

if ( initialized && tmp[1]=='h' )/* New msg is a hear */

ParseSensoryData(buf, Memry); /* parse the sound */

if ( Memry->HeardNewSound() ) /* respond to it */

Communicate(behavior, Memry, &sock);

Memry->ClearSound(); /* Undo the sound bit */

copy = FALSE; /* Leave the last msg in buf */

#if PRINT_MISSED_MSGS

else if ( initialized )

printf(``Player %d-%c skipped a message %.40s ...n

before %.40s ...n'',

Memry->MyNumber,Memry->MySide,buf,tmp);

#endif

if (copy)

strcpy(buf,tmp);

if ( buf[1] == 'h' ) /* also stop if it's a ``hear'' */

break;

MessageCounter++;

MessageCounter = 0;
[Noda]


next up previous contents
Next: I’m trying to run Up: Making Clients Previous: How do I set   Contents
RoboCup SoccerServer Manual Account
1999-07-03