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