예제 #1
0
/*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;
}
예제 #2
0
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);
}
예제 #3
0
/* 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;
	
}
예제 #4
0
ProcessImage::ProcessImage(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    setWindowTitle(tr("Capture"));
    ui->setupUi(this);
    timer = new QTimer(this);
    frame = new QImage(320,240,QImage::Format_RGB888);
    hav_video = false;

    initCamera();

    QString addr("192.168.43.2");
    ip.setAddress(addr);
    port = 8888;
    ui->lineEdit_ip->setText(addr);
    ui->lineEdit_port->setText(QString::number(port));
    connectTCP();

    connect(timer,SIGNAL(timeout()),this,SLOT(repaintFrame()));
    timer->start(100);

    connect(ui->pushButton_listen, SIGNAL(clicked()), this, SLOT(connectTCP()));
    connect(ui->pushButton_close, SIGNAL(clicked()), this, SLOT(closeTCP()));
}
예제 #5
0
void ProcessImage::repaintFrame()
{
    if(!vd->isOpen() || !vd->isStart()){
        initCamera();
        return;
    }

    rs = vd->get_frame((void **)&frame_yuv,&len);
    if(-1==rs)
    {
        timer->setInterval(3000);
        vd->stop_capturing();
        vd->close_device();
        initCamera();
        return;
     }
    frame_buf.setRawData((const char*)frame_yuv, len);
    vd->unget_frame();
    frame->loadFromData((uchar *)frame_buf.data(),len/*320 * 240 * 3 * sizeof(char)*/);

    if(m_client.isValid()){
        rs = m_client.write((const char *)&len, sizeof(len));
        m_client.flush();
        if(rs < 0){
            closeTCP();
            connectTCP();
        }
        rs = m_client.write((const char *)frame_buf.data(), len);
        m_client.flush();qDebug() << rs << "";
        if(rs < 0){
            closeTCP();
            connectTCP();
        }
    }
    else{
        closeTCP();
        connectTCP();
    }
    hav_video = true;
    this->update();
}
예제 #6
0
void CameraDialog::listenTCP()
{
    if(m_server.isListening()){
        closeTCP();
    }
    if(m_server.listen(ip, port)){
        connect(&m_server, SIGNAL(newConnection()), this, SLOT(newConnection()));
        ui->pushButton_listen->setEnabled(false);
        qDebug() << "listen...";
    }
    else{
        QMessageBox::warning(this, QString("Error!!!"), QString("填写本机IP,或者更换端口号后重试!!!"));
    }
}
예제 #7
0
void sJarvisNode::validateClient(QByteArray data)
{
    QString greet;
    greet += P_PACKETSTART ;
    greet += M_JARVISMSG;
    greet += P_PACKETSEPARATOR;
    greet += M_NODE_GREETING;
    greet += P_PACKETTERMINATOR;
    qDebug() << data << "/" << greet  ;
    if(data == greet)
    {
        disconnect(&m_tcpClient,SIGNAL(socket_rx(QByteArray)),this,SLOT(validateClient(QByteArray)));
        connect(&m_tcpClient,SIGNAL(socket_rx(QByteArray)),this,SLOT(data_rx(QByteArray)));
    }
    else
        closeTCP();
}
예제 #8
0
void QvisController::createTCPThread()
{
    if (ui->getPort() != 3490) {
        ui->setInfoText("Atlas is on port 3940");
        return;
    }
    
    ui->setConnectionStatus(true);

    tcpSocket = new QTcpSocket(this);
    
    connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readTCP()));
    connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));

    tcpSocket->connectToHost(ui->getIp(),ui->getPort());
    
    QObject::connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(closeTCP()));
    std::cout << "Connection button set to close" << std::endl;
    tcpSocket->write(getSendData(), 54);
    ui->setConnected();
}
예제 #9
0
void sJarvisNode::initTimeout()
{
    closeTCP();
    m_initTimeout.stop();
}
예제 #10
0
static status
NewDownload(int ssock)
{
	
	unsigned long total_packets;
	unsigned long n_packet;
	boolean exit;
	download_t header;
	void *packet;
	char name[MAX_MOVIE_LEN];

	u_size header_size;
	FILE *fd;
	/* Recibo el primer paquete */
	n_packet = 0;
	exit = FALSE;

	
	packet = receiveTCP(ssock);
	if(packet==NULL)
	{
	    raise(SIGINT);
	}
	header_size = GetDownloadPack(packet,&header);
	
	fd = fopen(header.title,"wb+");	
	strcpy(name,header.title);
	/* 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;
	
	while (!exit) {
		/* Recibo un paquete */
		fflush(0);
		packet = receiveTCP(ssock);
		if(packet==NULL)
		{
		    raise(SIGINT);
		}
		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;
	}
	printf("Termine de transmitir %s\n",name);
	fclose(fd);
	closeTCP(ssock);
	
	return OK;
}