[done] plane part to manage received IP/PORT from multicast group and connect to TCP socket.

[todo] still this f**king problem with thread conflicts when multiple planes connected!!!
This commit is contained in:
xdrm-brackets 2017-04-18 20:14:50 +02:00
parent d5f883add1
commit 095706b24f
2 changed files with 13 additions and 21 deletions

View File

@ -20,6 +20,7 @@ int DROP_MULTICAST_SERVER(const char* pAddr, const int pPort, int* pListenSock,
struct ip_mreq mcastReq;
*pListenSock = -1;
struct timeval timeout;
u_int reuse = 1;
/* [1] Création de la socket
@ -39,6 +40,13 @@ int DROP_MULTICAST_SERVER(const char* pAddr, const int pPort, int* pListenSock,
return -1;
}
/* 4. Notification d'utilisation multiple du même port */
if( setsockopt(*pListenSock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(u_int)) < 0 ){
close(*pListenSock);
return -1;
}
/* [2] On définit les infos de la socket
=========================================================*/

View File

@ -36,32 +36,15 @@ int open_communication(){
=========================================================*/
/* (1) Création socket multicast
/* (1) Création socket multicast client* (écoute)
---------------------------------------------------------*/
if( DROP_MULTICAST_SERVER(MCST_HOST, MCST_PORT, &mcast_socket, &udp) < 0 )
return 0;
// *un client multicast est en fait un serveur UDP, mais le terme persiste car le service est délivré par le CLIENT UDP
/* (2) Envoi séquence initialisation avion
---------------------------------------------------------*/
/* 1. Construction séquence d'initialisation */
// memcpy(buffer, numero_vol, sizeof(char)*6);
request.flags = BINDHEAD_TCP;
strcpy(request.addr, "000.000.000.000");
request.port = htons(0);
memcpy(buffer+sizeof(char)*0, &request.flags, sizeof(char));
memcpy(buffer+sizeof(char)*1, &request.addr, sizeof(char)*INET_ADDRSTRLEN);
memcpy(buffer+sizeof(char)*(1+INET_ADDRSTRLEN), &request.port, sizeof(unsigned short));
/* 2. Envoi séquence */
// if( sendto(mcast_socket, buffer, BINDHDR_LEN/sizeof(char) +1, 0, (struct sockaddr*) &udp, sizeof(struct sockaddr_in)) < 0 ){
// close(mcast_socket);
// return 0;
// }
// printf("* sent bind_header{flags = %d; addr = %s; port = %d;}\n", request.flags, request.addr, htons(request.port));
/* (3) Attente réponse SGCA -> adresse+port TCP
/* (2) Attente réponse SGCA -> adresse+port TCP
---------------------------------------------------------*/
/* 1. Attente réponse */
status = recv(mcast_socket, buffer, MAX_BUF_LEN, 0);
@ -74,7 +57,6 @@ int open_communication(){
/* 3. Vérification taille */
if( status < BINDHDR_LEN ){
printf("%d / %d\n", status, (int) BINDHDR_LEN);
close(mcast_socket);
return 0;
}
@ -85,6 +67,8 @@ int open_communication(){
memcpy(&request.addr, buffer, sizeof(char) );
memcpy(&request.addr, buffer+sizeof(char), sizeof(char)*INET_ADDRSTRLEN );
memcpy(&request.port, buffer+sizeof(char)*(1+INET_ADDRSTRLEN), sizeof(unsigned short) );
// on indian-switch
request.port = ntohs(request.port);
printf("* received bind_header{flags = %d; addr = %s; port = %d;}\n\n", request.flags, request.addr, request.port);