/* Escucha los pedidos de conexion para iniciar una descarga por parte del servidor */ status InitDownloader(void) { int ssock; /* Preparo el puerto que va a escuchar los pedidos de conexion de transferencia */ if( (passive_s=prepareTCP(client_host,client_port,prepareServer)) < 0 ) { return FATAL_ERROR; } if( (listenTCP(passive_s,10)) < 0 ) { return FATAL_ERROR; } while(1) { ssock = acceptTCP(passive_s); setSocketTimeout(ssock,TIMEOUT_DEFAULT); switch(fork()){ case 0: NewDownload(ssock); exit(EXIT_SUCCESS); break; case -1: return FATAL_ERROR; break; default: /* Sigo escuchando */ break; } close(ssock); } closeTCP(passive_s); return OK; }
CameraDialog::CameraDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CameraDialog) { ui->setupUi(this); frame = new QImage(320,240,QImage::Format_RGB888); frame_yuv = new uchar[320*240*3]; p_yuv = frame_yuv; // label = new QLabel(); hav_video = false; QString addr("192.168.1.52"); ip.setAddress(addr); port = 8888; ui->lineEdit_ip->setText(addr); ui->lineEdit_port->setText(QString::number(port)); // listenTCP(); connect(ui->pushButton_set, SIGNAL(clicked()), this, SLOT(setnet())); connect(ui->pushButton_listen, SIGNAL(clicked()), this, SLOT(listenTCP())); connect(ui->pushButton_close, SIGNAL(clicked()), this, SLOT(closeTCP())); // connect(&m_client, SIGNAL(disconnected()), this, SLOT(closed())); // m_client.connectToHost(ip, port); // connect(&m_tim, SIGNAL(timeout()), this, SLOT(clientsend())); // m_tim.start(3000); }
/*DEPRECATED*/ static status ListenMovie(FILE *fd,char *port,char *ticket) { int passive_s,ssock; unsigned long total_packets; unsigned long n_packet; boolean exit; download_t header; download_start_t start; void *packet; void *data; u_size size; u_size header_size; /* Preparo el puerto que va a escuchar la conexion */ if( (passive_s=prepareTCP(client_host,port,prepareServer)) < 0 ) { return FATAL_ERROR; } if( (listenTCP(passive_s,10)) < 0 ) { return FATAL_ERROR; } /* Mando la senial al server pidiendo el inicio de la descarga */ strcpy(start.port,port); strcpy(start.ip,client_host); strcpy(start.ticket,ticket); size = GetDownloadStartData(start, &data); if( SendSignal(__DOWNLOAD_START_OK__, data, size) == ERROR ) return ERROR; free(data); exit = FALSE; n_packet = 0; ssock=acceptTCP(passive_s); while (!exit) { /* Recibo un paquete */ packet = receiveTCP(ssock); if(packet==NULL) { close(socket); return TIMEOUT_ERROR; } header_size = GetDownloadPack(packet,&header); /* Lo bajo a disco */ PutFileData(fd,_FILE_SIZE_, header.n_packet,packet+header_size,header.size); /* Verifico la cantidad total de paquetes a descargar */ total_packets = header.total_packets; free(packet); n_packet++; /* Me fijo si llego a la cantidad total de paquetes bajados */ if( n_packet >= total_packets ) exit = TRUE; } closeTCP(ssock); closeTCP(passive_s); return OK; }