0
我必須發送一些命令到UDP套接字服務器並獲得重播,下面的代碼工作正常,這是在C/C + +,我得到成功的響應從服務器使用它。PHP發送十六進制數據到套接字
typedef struct{
unsigned char type; //type
char unsignedfunctionID;
unsigned short reserved; //Reserved
int unsignediDevSn; // serial number 4-byte
unsigned char data [32]; // 32 bytes of data
unsigned int sequenceId; // serial number
unsigned char extern_data [20];
}PacketShortAccess;
發送到插座
PacketShortAccess statusCommand;
statusCommand={0};
statusCommand.type=0x19;
statusCommand.unsignedfunctionID=0x20;
statusCommand.reserved=0; //Reserved
statusCommand.unsignediDevSn=serialNumebr; serial number 4-byte
char sendData[sizeof(statusCommand)];
memcpy(sendData, &statusCommand, sizeof(statusCommand));
sendto(sockfd,sendData,sizeof(sendData),0,(struct sockaddr *)&servaddr,sizeof(servaddr));
現在我需要在PHP中使用相同的命令格式,
我試圖像
//this the command format I am getting while printing on c++ code
$command="19 ffb0 0 0 ff88 d 38 19 ffd0 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ";
socket_sendto($sock, $command, strlen($command) , 0 , $server , $port)
但我沒有得到任何來自服務器的響應,我可以在php中重新編寫上面的C++代碼。
「*命令格式,而對C印花++代碼*我得到」 你怎麼打印此? – alk
我正在打印這樣的數據:'for(int i = 0; i <64; i ++) \t \t cout << hex << static_cast(sendData [i])<<「」; –
CodeDezk