I want to send the following data using UDP.
$packet[0] = 0x01;
$packet[1] = 0x11;
$packet[2] = 0xF1;
$packet[3] = 0xD1;
$packet[4] = 0xF1;
$packet[5] = 0xB1;
$packet[6] = 0xC1;
$packet[7] = 0xF1;
I used int socket_sendto ( resource $socket , string $buf , int $len , int $flags , string $addr [, int $port = 0 ] ) function to send.
But it accepts a string.How can i convert interger array and send data to UDP server, So that data is treated as 1 byte each.
Thanks.
Sending data using UDP
Moderator: General Moderators
Re: Sending data using UDP
As a string that would be: $packet="\x01\x11\xf1\xd1\xf1\xb1\xc1\xf1";
You could also loop through your array
You could also loop through your array
Code: Select all
$string="";
foreach($packet as $value)
{
$string.=chr(hexdec($value));
}Re: Sending data using UDP
PROBLEM SOLVED
Thanks for your Reply. I have checked your code.It worked by ::
and also by
I have same probelm in reverse direction while receiving the packet.
Function for receive using UDP accepts string.But I have to treat it as Hexadecimal value and add in array.
How can i do it.
Thanks for your Reply. I have checked your code.It worked by ::
Code: Select all
foreach($packet as $value) {
$string.= chr($value);
}
Code: Select all
$packet = "\x01\x11\xF1\xD1\xF1\xB1\xC1";
Function for receive using UDP accepts string.But I have to treat it as Hexadecimal value and add in array.
How can i do it.