int main(int argc, char *argv[]){
    struct sockaddr_in insock, outsock ;
    int s_onBoard, s_sim, recv_len, slen = sizeof(outsock) ;
    struct timeval tv;
    int retval, mode;
    float buf [LEN_BUF_SENSOR];

    sscanf(argv[1],"%d",&mode);
    printf("le mode est %d \n", mode);
    switch (mode){
        case '1' :
        {//100Hz
        tv.tv_sec=0;
        tv.tv_usec=10000;

        break;
        }
        case '2' :
        {//50Hz
        tv.tv_sec=0;
        tv.tv_usec=20000;
        break;
        }
        default:
        break;

    }

    if (initSocket(IMU_PORT,MOV_PORT,s_onBoard, s_sim, SIM_IP,insock,outsock)==1){
        printf ("init success\n");

        while(1){
        printf("mode value %d\n", mode);
             /*if ((recv_len = recvfrom(s_onBoard, buf, LEN_BUF_SENSOR, 0, (struct sockaddr *) &outsock, &slen)) == -1)
        {
            die("recvfrom()");
        */

            if(mode == 1 ){
                retval= select(1,NULL,NULL,NULL, &tv);
                if (retval == -1)
                    perror("select()");
                else
                    printf("I have waited 10 mseconds.\n");

            }

            else if(mode == 2 ){
                retval= select(1,NULL,NULL,NULL, &tv);
                if (retval == -1)
                    perror("select()");
                else
                printf("I have waited 20 mseconds.\n");

            }

    }
}
return 1;
}
Exemplo n.º 2
0
void sfl_receiver_set_sFlowRcvrPort(SFLReceiver *receiver, uint32_t sFlowRcvrPort) {
  receiver->sFlowRcvrPort = sFlowRcvrPort;
  // update the socket structure
#ifdef SFLOW_DO_SOCKET
  initSocket(receiver);
#endif
}
Exemplo n.º 3
0
void sfl_receiver_init(SFLReceiver *receiver, SFLAgent *agent)
{
    /* first clear everything */
    memset(receiver, 0, sizeof(*receiver));

    /* now copy in the parameters */
    receiver->agent = agent;

    /* set defaults */
    receiver->sFlowRcvrMaximumDatagramSize = SFL_DEFAULT_DATAGRAM_SIZE;
    receiver->sFlowRcvrPort = SFL_DEFAULT_COLLECTOR_PORT;

#ifdef SFLOW_DO_SOCKET
    /* initialize the socket address */
    initSocket(receiver);
#endif

    /* preset some of the header fields */
    receiver->sampleCollector.datap = receiver->sampleCollector.data;
    putNet32(receiver, SFLDATAGRAM_VERSION5);
    putAddress(receiver, &agent->myIP);
    putNet32(receiver, agent->subId);

    /* prepare to receive the first sample */
    resetSampleCollector(receiver);
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) {
  init();
  //init_error();
  while (1) {
    try {
      if (!sock) {
        initSocket();
      }
      sock->receiveFile(CONFIG->GetTmpfile_path() + "temp.bott");
    } catch (Exception & e) {
      if (sock) {
        delete sock;
        sock = NULL;
      }
      LOG((string) "Exception caught: " + e.what());
      LOG("Network Error, trying to reconnect after 5 seconds");
      sleep(5);
      continue;
    }

    parse_bott();
    if (bott->Gettype() == DO_CHALLENGE)
      dochallenge();
    else if (bott->Gettype() == NEED_JUDGE || bott->Gettype() == DO_TESTALL ||
        bott->Gettype() == DO_PRETEST)
      dojudge(bott->Gettype());
    else if (bott->Gettype() == DO_INTERACTIVE)
      dointeractive();
    delete bott;
  }
  return 0;
}
Exemplo n.º 5
0
int main(int argC, char** argV) {
   if (argC != 3){
      printf("Usage: <filename> <address>\n");
      return -1;
   }

  // Arg1 is file to be transferred
   filename = argV[1];

  // Arg2 is address
   char* address = argV[2];

   file = fopen ( filename , "r" );
   if (file==NULL) {fputs ("File error",stderr); exit (1);}

   ph = (PacketHolder*) malloc(sizeof(PacketHolder));
   initPacketHolder(ph);
   initSocket(address);

   pthread_t thread1, thread2;
   int iret1, iret2;

   iret1 = pthread_create( &thread1, NULL, makePackets, (void*) NULL);
   iret2 = pthread_create( &thread2, NULL, sendPackets, (void*) NULL);

   pthread_join( thread1, NULL);
   pthread_join( thread2, NULL);

   close(sock);
   exit(0);
}
Exemplo n.º 6
0
void Socket::initAsTcpServer(const std::string& _hostLocal, unsigned _portLocal, unsigned _listenQueue) {
    type = TCP_SERVER;
    hostLocal = _hostLocal;
    portLocal = _portLocal;
    status = _listenQueue;
    initSocket(false);
}
Exemplo n.º 7
0
int main(int argc, char* argv[])
{
    initSocket();

    int n;
    char buf[1024];
    pthread_t senderThread;
    int ret = pthread_create(&senderThread, NULL, senderThreadMain, NULL);
    if (0 != ret) {
        fprintf(stderr, "senderThread create failed!\n");
    }

    for (;;) {
        memset(buf, 0, sizeof(buf));
        n = recv(s_socket, buf, 1024, 0);
        if (0 < n) {
            printf("\n%s", buf);
            if (buf[0], '\n') {
            	printf("client>");
                fflush(stdout);
            }
        }
        else if (0 == n) {
        	printf("server is closed, exiting!\n");
        	break;
        }
        else {
            printf("client>");
        }
    }

    finalSocket();
    return 0;
}
Exemplo n.º 8
0
KMessageSocket::KMessageSocket (const QString& host, quint16 port, QObject *parent)
  : KMessageIO (parent)
{
  mSocket = new QTcpSocket ();
  mSocket->connectToHost (host, port);
  initSocket ();
}
Exemplo n.º 9
0
KMessageSocket::KMessageSocket (QHostAddress host, quint16 port, QObject *parent)
  : KMessageIO (parent)
{
  mSocket = new QTcpSocket ();
  mSocket->connectToHost (host.toString(), port);
  initSocket ();
}
Exemplo n.º 10
0
KMessageSocket::KMessageSocket (int socketFD, QObject *parent)
  : KMessageIO (parent)
{
  mSocket = new QTcpSocket ();
  mSocket->setSocketDescriptor (socketFD);
  initSocket ();
}
Exemplo n.º 11
0
void Control :: setSettingsSocket() {
	bool ok;
	int port = QInputDialog :: getInt(this, tr("Port"), tr("Enter Port, range 0....65535"), 10001, 0, 65535, 1, &ok);
	if (ok) {
		this->port = port;
	} else {
		setSettingsSocket();
	}
	
	QString ipAddress;
	QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
	for (int i = 0; i < ipAddressesList.size(); ++i) {
		if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) {
			ipAddress = ipAddressesList.at(i).toString();
			break;
		}
	}
	if (ipAddress.isEmpty()) {
		ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
	}
	
	ipAddress = QInputDialog :: getText(this, tr("ip"), tr("Enter ip of Magic Ball applications"), QLineEdit::Normal, ipAddress, &ok);
	if (ok && !ipAddress.isEmpty()) {
		this->ipAddress = ipAddress;
		if (!(initSocket())) {
			QMessageBox::critical(0, "Control", "ip " + ipAddress + " something is wrong, maybe port already in use someone?");
			setSettingsSocket();
		}
	}
}
Exemplo n.º 12
0
// --------------------------------------------------------------------
// main
// --------------------------------------------------------------------
int main(int argc, char*argv[]) 
{    
    parseArgs(argc, argv);

    struct sigaction a;
    a.sa_handler = traitementInterrupt;      /* fonction à lancer */
    sigemptyset(&a.sa_mask);    /* rien à masquer */
    
    sigaction(SIGTSTP, &a, NULL);       /* pause contrôle-Z */
    sigaction(SIGINT,  &a, NULL);       /* fin contrôle-C */
    sigaction(SIGTERM, &a, NULL);       /* arrêt */
    sigaction(SIGSEGV, &a, NULL);       /* segmentation fault ! */

    int sock=0;
    initSocket(sock);
    sock_=sock;
    
    ZFile file;
    initFile(&file);
    file_=&file;
    
    while(1) {
	bool close=false;
        processPacket(sock, &file, false, close);
	if (close) {
	    file.close();
	    initFile(&file);
	    file_=&file;
	}
    }
    return(EXIT_SUCCESS);
}
Exemplo n.º 13
0
void Connection::onConnect(int fd, int r, void *data)
{
	int sockerr = 0;
	socklen_t errlen = sizeof(sockerr);

	//remove all event
	pEventLoop->removeEventListener(sSocket.getFd(), EV_IO_ALL);
	
	//remove timer
	if(nTimeout){
		pEventLoop->stopTimer(nTimerId);
	}
	
	//check fd
	if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &sockerr, &errlen) == -1){
		sockerr = errno;
	}
	
	//error
	if(sockerr){
		nError = sockerr;
		close();
		return ;
	}
	
	initSocket();
	
	EV_INVOKE(cbConnect, this);
}
Exemplo n.º 14
0
int main(int argc, char* argv[])
{
	SetErrorMode(SEM_NOGPFAULTERRORBOX ); 
	char INIfilename[256]="EOJ\\data.ini";
	char IP[30]="127.0.0.1";
	for(int i = 1;i<=3;i++){
		StatusSocket socketData;
		/*
		if(argc>0){
			socketData.statusId=atoi(argv[1]);  
		}else{
			return 0;
		}
		if(argc>1){
			socketData.statusType=atoi(argv[2]); 
		}
		if(argc>2){
			strcpy(INIfilename,argv[3]);
		}
		*/
		socketData.statusId = i;
		socketData.statusType = 1;
		int port=GetPrivateProfileInt("Tool","Port",PORT,INIfilename);
		initSocket(port,IP);
		send(client,(const char*)&socketData,sizeof(socketData),0);
		closesocket(client);
	}
	WSACleanup();
	Sleep(1000);
	
	return 0;
}
Exemplo n.º 15
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    //initialize main window
    initWindow();

    //initialize some variables for first use
    initFirstUse();

    //restore old settings
    restoreSettings();

    //initalize upload process
    initProcess();

    //connects
    connect(procUpload,SIGNAL(readyReadStandardOutput()),this,SLOT(affichUpload()));
    connect(procUpload,SIGNAL(readyReadStandardError()),this,SLOT(affichUpload()));
    connect(ui->buttonExit, SIGNAL(clicked()), qApp, SLOT(quit()));

    //initialize build directory if there is an argument
    initBuildDirectory();

    //initalize sockets
    initSocket();
}
Exemplo n.º 16
0
int main(int argc, char const *argv[])
{
	if (argc != 3) {
		fprintf(stdout, "%s\n", "input args port ip");
		return 0;
	}
	initSocket(argv[1], argv[2]);
	return 0;
}
Exemplo n.º 17
0
main()
{	
	//printf("网络初始化成功!\n");
	initUI();
	r=initSocket();	
	if(r==-1) exit(-1);
	signal(SIGCHLD,handle);
	if(fork())
	{
		//输入,发送
		char buf[256];
		while(1)
		{
			mvwgetstr(wmsg,1,1,buf);
			//buf[r]=0;
			send(fd,buf,strlen(buf),0);			
			//wclear(wmsg);
			//box(wmsg,0,0);
			refresh();
			wrefresh(wmsg);
			wrefresh(winfo);
		}
	}
	else
	{
		
		//接收,显示
		char buf[256];
		int line=1;
		while(1)
		{			
			r=recv(fd,buf,255,0);
			if(r==-1) break;
			if(r==0) break;
			buf[r]=0;
			mvwaddstr(winfo,line,1,buf);
			line++;			
			if(line>=(LINES-3))
			{
				wclear(winfo);
				line=1;
				box(winfo,0,0);				
			}
			
			
			wmove(wmsg,1,1);
			touchwin(wmsg);
			refresh();
			wrefresh(winfo);			
			wrefresh(wmsg);
		}
		exit(-1);
	}
		
	destroy();
}
Exemplo n.º 18
0
Client::Client(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
{
	ui.setupUi(this);
	Client::m_pCurWidget = this;
	Client::udpSocket = NULL;

	initSocket();
	sendMsg("Hello!");
}
Exemplo n.º 19
0
QAMQP::Network::Network( QObject * parent /*= 0*/ ):QObject(parent)
{
    qRegisterMetaType<QAMQP::Frame::Method>("QAMQP::Frame::Method");

    buffer_.reserve(Frame::HEADER_SIZE);
    timeOut_ = 1000;
    connect_ = false;

    initSocket(false);
}
Exemplo n.º 20
0
int main(int argc, char* argv[])
{
    initSocket();

    startTcpListen();

    deinitSocket();

    return 0;
}
Exemplo n.º 21
0
int main(){

	signal(SIGCHLD,handle);
	r = initSocket();
	if(r == -1){
		printf("init socket :%m\n");
		exit(-1);
	}
	printf("Init socket success.....\n");

	initUI();

	if(fork()){
		//input ,send
		char buf[256];	
		while(1){
			r = mvwgetstr(wmsg,1,1,buf);
			send(fd,buf,strlen(buf),0);
			wclear(wmsg);
			box(wmsg,'|','-');
			refresh();
			wrefresh(wmsg);
		}
	}else{
		//receive ,show
		char buf[256];
		int line = 1;
		while(1){
			r = recv(fd,buf,255,0);
			if(r == -1)break;
			buf[r] = 0;
			mvwaddstr(winfo,line,1,buf);
			line++;

			if(line >= (LINES-6)){
				wclear(winfo);
				line = 1;
				box(winfo,'|','-');
			}

			wmove(wmsg,1,1);
			touchwin(wmsg);

			refresh();
			wrefresh(winfo);
			wrefresh(wmsg);

		}
		exit(0);
	}

	destroy();

	return 0;
}
Exemplo n.º 22
0
int SocketServer::init(Server *server)
{
	int ret;
	this->server = server;
	ret = initSocket();
	if (ret)
		return ret;

	ret = initSSL();
	return ret;
}
Exemplo n.º 23
0
int main(int argc, char* argv[])
{

  int sd, rc;
  unsigned int port = 0;
  unsigned int episode = 0;

  /* Check arguments, assign port and episode values */
  if(argc < 4)
  {
    printf("usage: %s <server> <port> <episode> [<agent-specific parameters>]\n", argv[0]);
    return 1;
  }
  else if((port = atoi(argv[2])) == 0)
  {
    printf("The port number is invalid\n");
    return 1;
  }
  else if((episode = atoi(argv[3])) == 0)
  {
    printf("The episode number is invalid\n");
    return 1;
  }

  rc = initSocket(argv[1], port, &sd);
  if(rc < 0)
  {
    printf("could not initialize socket ");
    return 1;

  }

  // Now start to send the data
  rc = performInit(sd, argc - 4, (const char**)&argv[4]);
  if(rc < 0)
  {
    perror("failed intialization of the agent");
    return 1;
  }
  for(unsigned int i = 0; i < episode; ++i)
  {
    rc = performEpisode(sd);
    if(rc < 0) break;
  }
  performCleanup();
  close(sd);

  if(rc >= 0)
  {
    return 0;
  }
  return rc;
}
Exemplo n.º 24
0
int main(int argc, char* argv[])
{
	int sock = initSocket(9889);
	//printf("%d\n",sock);
	listen(sock,3);
	while(1)
	{
		int client = accept(sock,NULL,NULL);
		printf("Connected succesful!\n");
		close(client);
	}
	return 0;
}
Exemplo n.º 25
0
Arquivo: client.c Projeto: rif/gocrpc
int main(int argc, char *argv[]) {
  int sockfd;
  char response[MAXRCVLEN];
  
  sockfd = initSocket(SERVER_ADDR, PORTNUM);
  
  rpcCall(sockfd, "Arith.Multiply", "{\"A\": 2, \"B\": 3}", response);

  printf("%s\n", response);
  
  close(sockfd);
  return 0;
}
Exemplo n.º 26
0
MainDialog::MainDialog(QWidget *parent,QString ipAddr,QString name) :
    QDialog(parent),
    ui(new Ui::MainDialog)
{
    ui->setupUi(this);
    this->setWindowFlags( windowFlags() | Qt::WindowMinimizeButtonHint );
    this->ipAddr = ipAddr;
    this->name = name;
    ct = new ClockThread(this,true);
    connect(ct,&ClockThread::updateMainToClock,this,&MainDialog::updateColckData);
    ct->start();
    init();
    initSocket();
}
Exemplo n.º 27
0
int *init_ais_decoder(char * host, char * port ,int show_levels,int _debug_nmea,int buf_len,int time_print_stats){
    
	debug_nmea=_debug_nmea;
	if(debug_nmea)
		fprintf(stderr,"Log NMEA sentences to console ON\n");
	else
		fprintf(stderr,"Log NMEA sentences to console OFF\n");
		
    if (!initSocket(host, port)) {
        return EXIT_FAILURE;
    }
    if (show_levels) on_sound_level_changed=sound_level_changed;
    on_nmea_sentence_received=nmea_sentence_received;
	initSoundDecoder(buf_len,time_print_stats); 
	return 0;
}	
Exemplo n.º 28
0
void Server::initServer(int port){
	createSharedMemory();
	int id = fork();

	struct stat st;
	if (stat(FIFO_NAME, &st) != 0)
		mkfifo(FIFO_NAME, 0666);

	if(id > 0){
		initSocket(port);
		wait();
	}
	else if (id == 0){
		consumeData();
	}
}
Exemplo n.º 29
0
int main(int argc, char* argv[])
{

	SetErrorMode(SEM_NOGPFAULTERRORBOX ); 
	char INI_filename[256]="D:\\OJ\\GDOJ\\data.ini";
	char IP[30]="127.0.0.1";
	int languageId=1;
	JUDGE_DATA j;

	if(argc>0){
		j.solutionId=atoi(argv[1]);  
	}else{
		return 0;
	}
	if(argc>1){
		languageId=atoi(argv[2]); 
	}
	if(argc>2){
		strcpy(INI_filename,argv[3]);
	}
	
//	j.solutionId=45;  
//	int languageId=1; 

	int port;
	char languageName[100]={0};
	char keyname[110]={0};


	sprintf(keyname,"Language%d",languageId);
	GetPrivateProfileString("Language",keyname,"",languageName,sizeof(languageName),INI_filename);
	GetPrivateProfileString("JudgeIP",languageName,"127.0.0.1",IP,sizeof(IP),INI_filename);

	port=GetPrivateProfileInt("Tool","Port",PORT,INI_filename);
	



	initSocket(port,IP);

	send(sClient,(const char*)&j,sizeof(j),0);
	
	closesocket(sClient);
	WSACleanup();
	Sleep(1000);
	return 0;
}
Exemplo n.º 30
0
NetBase::NetBase(int outqueuesize)
: senders(outqueuesize)
{
    randomgen = new csRandomGen;
    
    pipe_fd[0] = 0;
    pipe_fd[1] = 0;

    if (socklibrefcount==0 && initSocket())
        ERRORHALT ("couldn't init socket library!");
    socklibrefcount++;

    NetworkQueue.AttachNew(new NetPacketQueueRefCount(MAXQUEUESIZE));
    if (!NetworkQueue)
        ERRORHALT("No Memory!");

    ready=false;
    totaltransferout  = 0;
    totaltransferin   = 0;
    totalcountin      = 0;
    totalcountout     = 0;
    
    profs = new psNetMsgProfiles();
    
    // Initialize the timeout to 30ms, adds 30ms of latency but gives time for packets to coalesce
    timeout.tv_sec = 0;
    timeout.tv_usec = 30000;

    accessPointers.msgstrings = NULL;
    accessPointers.msgstringshash = NULL;
    accessPointers.engine = NULL;

    logmsgfiltersetting.invert = false;
    logmsgfiltersetting.filterhex = true;
    logmsgfiltersetting.receive = false;
    logmsgfiltersetting.send = false;

    input_buffer = NULL;
    for(int i=0;i < NETAVGCOUNT;i++)
    {
        sendStats[i].senders = sendStats[i].messages = sendStats[i].time = 0;
    }
    for(int i =0;i < RESENDAVGCOUNT;i++)
        resends[i] = 0;
    avgIndex = resendIndex = 0;
    lastSendReport = csGetTicks();
}