/** * Create a set of connection, according to the .ini file's options * and put it in the global ag->connArr (struct Connexion array) */ void createInterfaces(struct agrego *ag) { char arg[50]; char *ipadress; int port; char *ipadress_dest; int port_dest; int ponderation; int i; for (i = 0; i < ag->nbConn; i++) { sprintf(arg, "Link_%d:%s_ip_address_private", i+1, getEndpoint()); ipadress = xiniparser_getstring(arg, NULL); if (ipadress == NULL || strlen(ipadress) == 0) { sprintf(arg, "Link_%d:%s_ip_address_public", i+1, getEndpoint()); ipadress = xiniparser_getstring(arg, NULL); if (ipadress == NULL) { fprintf(stderr, "cannot read the %s_ip_address in the .ini file: %s\n", getEndpoint(), arg); exit(EXIT_FAILURE); } } sprintf(arg, "Link_%d:%s_port", i+1, getEndpoint()); port = xiniparser_getint(arg, -1); if (port == -1) { fprintf(stderr, "cannot read the %s_port in the .ini file: %s\n", getEndpoint(), arg); exit(EXIT_FAILURE); } sprintf(arg, "Link_%d:%s_ip_address_public", i+1, getOtherEndpoint()); ipadress_dest = xiniparser_getstring(arg, NULL); if (ipadress_dest == NULL) { fprintf(stderr, "cannot read the %s_ip_address in the .ini file: %s\n", getOtherEndpoint(), arg); exit(EXIT_FAILURE); } sprintf(arg, "Link_%d:%s_port", i+1, getOtherEndpoint()); port_dest = xiniparser_getint(arg, -1); if (port_dest == -1) { fprintf(stderr, "cannot read the %s_port in the .ini file: %s\n", getOtherEndpoint(), arg); exit(EXIT_FAILURE); } sprintf(arg, "Link_%d:coefficient", i+1); ponderation = xiniparser_getint(arg, -1); ag->maxWeight = (ag->maxWeight < ponderation) ? ponderation : ag->maxWeight; if (ponderation == -1) { fprintf(stderr, "cannot read the coefficient in the .ini file: %s\n", arg); exit(EXIT_FAILURE); } ag->connArr[i] = initConnexion(port, ipadress, port_dest, ipadress_dest, ponderation); } }
RemoteControlInterface::RemoteControlInterface(QObject* parent): QObject(parent) { socket = new QTcpSocket(this); connect(socket, SIGNAL(connected()), this, SLOT(initConnexion())); connect(socket, SIGNAL(disconnected()), this, SLOT(onConnexionLost())); connect(socket, SIGNAL(readyRead()), this, SLOT(read())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(disconnected())); blockSize = 0; }
int main (int argc, char *argv[]) { struct sockaddr_in Connect,Data,Client; char segPerdu [7]; int descData,descConnect; int portData=8080; int portConnect; int numSeg=0; socklen_t adrsize=sizeof(Client); //Initialisation du port de connexion if(argc ==2){ portConnect = atoi(argv[1]); printf("Le port de Connection est :%d\n",portConnect); } else { printf("Pas le bon nombre d'arguments en entrée\n"); return 0; } initSocket(&descConnect,portConnect,Connect); initConnexion(descConnect,portData,(struct sockaddr*) &Client); //printf("Data %d %d\n", ntohl(Data.sin_addr.s_addr), ntohs(Data.sin_port)); initSocket(&descData, portData, Data); FILE* fichier=openFich(descData,(struct sockaddr*) &Client,adrsize); fd_set readset; struct timeval tv; tv.tv_sec = 3; while(1){ FD_ZERO(&readset); FD_CLR(0, &readset); //printf("test1\n"); FD_SET(descData, &readset); //printf("Erreur avant select\n"); if(select(descData+1, &readset, NULL, NULL,&tv)==-1){ perror("select"); } //printf("Erreur après select\n"); numSeg++; //printf("test3\n"); if (FD_ISSET(descData, &readset)) { printf("Erreur de récéption\n"); sleep(3); //memset(segPerdu,0,7); //recvfrom(descData,segPerdu,RCVSIZE,0, (struct sockaddr*) &Data,&adrsize); //printf("Ce segment s'est égaté : %d\n", atoi(segPerdu)); }else{ printf("Envoi\n"); envoi(descData,numSeg,fichier,(struct sockaddr*) &Client,adrsize); /* sth to snd */ } } }