#include <WScom.h>
#include <WSCfunctionList.h>
#include <WSCbase.h>
//----------------------------------------------------------
//Function for the event procedure
//----------------------------------------------------------
#include <newwin000.h>
void udpread(WSCbase* object){
  char buffer[16];
  long read_len = newvudp_000->read((WSCuchar*)buffer,16);
  if (read_len < 16){
    return;
  }
  WSCstring from_addr = newvudp_000->getDestAddr();
  if (!strcmp(buffer,"update")){
    long i;
    long num = newlist_001->getNum();
    WSCbool exist = False;
    for(i=0; i<num; i++){
      WSCstring item = newlist_001->getItem(i);
      if (!strcmp(item,from_addr)){
        exist = True;
        break;
      }
    }
    if (exist == False){
      newlist_001->addItem(from_addr);
    }
  }else if (!strcmp(buffer,"del")){
    long i;
    long num = newlist_001->getNum();
    for(i=0; i<num; i++){
      WSCstring item = newlist_001->getItem(i);
      if (!strcmp(item,from_addr)){
        newlist_001->delPos(i);
        break;
      }
    }
  }
}
static WSCfunctionRegister  op("udpread",(void*)udpread);
