//-------------------------------------------------------------- void testApp::setup(){ vidGrabber.setVerbose(true); vidGrabber.initGrabber(320,240); colorImg.allocate(320,240); grayImage.allocate(320,240); grayDiff.allocate(320,240); colorPin.allocate(320, 120); grayPin.allocate(320,120); moviendo = -1; roiPts = new ofPoint[4]; ultimaBarra = false; cargaConfig(); // ofSetFullscreen(true); ofEnableAlphaBlending(); }
int main (void) { struct sockaddr_in s_addr; struct sockaddr_in c_addr; key_t smkey; int port; // Leemos el fichero config.dat clancy config; // Configuramos los sockets config = cargaConfig(); port=config.port; if (port < 1024 || port > 65535){ write(1, " [Clancy] Invalid port!!\n", 25); exit(EXIT_FAILURE); } sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sockfd < 0){ write(1, " [Clancy] An error occurs while trying to create the socket TCP...\n", 67); exit(EXIT_FAILURE); } bzero (&s_addr, sizeof(s_addr)); s_addr.sin_family = AF_INET; s_addr.sin_port = htons(port); s_addr.sin_addr.s_addr = INADDR_ANY; if (bind(sockfd, (void *) &s_addr, sizeof(s_addr)) < 0){ write(1, " [Clancy] Binding error!!\n", 26); close (sockfd); exit(EXIT_FAILURE); } signal(2, controlC); signal(14, sigAlarm); smkey = ftok ("main.c", 1); if (smkey == (key_t) -1) { perror ("smkey error\n"); exit (-1); } SHM = shmget (smkey, sizeof (int), IPC_CREAT | 0600); if (SHM < 0){ perror ("shmget"); return -1; } estado = shmat (SHM, 0, 0); if (estado == NULL){ perror ("shmat"); return -1; } clrscr(); fflushnou(); write(1,"Clancy Wiggum, the Law\n", 23); write (1, "Esperant peticions...\n\n",23); listen(sockfd, 5); socklen_t c_len = sizeof (c_addr); int error; while (1){ newsock = accept(sockfd, (void *) &c_addr, &c_len); if (newsock < 0){ write (1, " [Clancy] An error occurs while trying to accept an incoming connection!!\n", 74); close (sockfd); exit(EXIT_FAILURE); } error = tramaIn(); if (error==0){ muestraEstado(); enviaRespuesta(config); write (1,"\nEsperant peticions...\n\n",24); alarm(config.periodo); } close (newsock); } return EXIT_SUCCESS; }