2017-05-31 140 views
0

環境:Windows套接字編程使用VC++ 2010(UDP)廣播GVCP不正常

GVCP:GigE視覺控制協議

GVCP = UDP +(GVCP報頭數據+有效載荷數據)。所以基本上在上面的一個UDP只能

用於檢測千兆傳感器(攝像機),需要先播出一GVCP包(含Gvcp有效載荷數據),利用廣播地址255.255.255.255

,但我只能夠播放通過192.168.1.255當我改變廣播地址255.255.255.255沒有什麼可見的線鯊魚也沒有其他機器上(如參見絲鯊)

所以問題是不能夠使用使用UDP IP 255.255.255.255廣播/ WinSock

回答

0

能夠啓動broadcas在GVCP數據包中,它只是一個插座創建錯誤,正確的錯誤如下

//---------------------DATA SENDER------------------------------ 
     struct sockaddr_in Sender_addr; 
     int  Sender_addrlen  = sizeof(Sender_addr);  
     Sender_addr.sin_family  = AF_INET; 
     Sender_addr.sin_port  = htons(CAMPORT);    //BROADCAST_PORT); 
     Sender_addr.sin_addr.s_addr = inet_addr("255.255.255.255"); //Broadcast 
    IP Here"); 



//---------------------DATA RECEIVER---------------------------- 
     struct sockaddr_in Recv_addr; 
     int  Recv_addrlen  = sizeof(Recv_addr); 
     Recv_addr.sin_family  = AF_INET; 
     Recv_addr.sin_port   = htons(PCPORT); 
     Recv_addr.sin_addr.s_addr = INADDR_ANY; 

     if(bind(sock,(sockaddr*)&Recv_addr,sizeof(Recv_addr))<0)  
     { 
      perror("bind"); 
      _getch; 
      closesocket(sock); 
     } 

//and then send command for GVCP packet (GVCP packet Structure is) 

     TxBuff[0] = 0x42; 
     TxBuff[1] = 0x01;  
     TxBuff[2] = 0x00; 
     TxBuff[3] = 0x02; 
     TxBuff[4] = 0x00; 
     TxBuff[5] = 0x00; 
     TxBuff[6] = 0x00; 
     TxBuff[7] = 0x02; 

    if(sendto(sock,TxBuff,TxBuffSize,0,(struct sockaddr 
    *)&Sender_addr,sizeof(Sender_addr)) <0) 
       { 
       perror("send: error "); 
       _getch(); 
       closesocket(sock);    
      }