ID: 31090 Updated by: [EMAIL PROTECTED] Reported By: ifirla at aegissrl dot it Status: Bogus Bug Type: Sockets related Operating System: Debian GNU/Linux 3.0 PHP Version: 4.3.9 New Comment:
you need to pack() if you want to send a 32 bit integer Previous Comments: ------------------------------------------------------------------------ [2004-12-15 01:05:04] [EMAIL PROTECTED] Here's the proto for fwrite(): int fwrite ( resource handle, string string [, int length]) See the 3rd parameter? Give the length to the function. Also note the 2nd parameter type.. No bug here. ------------------------------------------------------------------------ [2004-12-14 17:18:04] ifirla at aegissrl dot it Description: ------------ an array holds elements of various types: ascii|integer|integer|integer|integer in a foreach loop, sending each element to a socket opened with fsockopen sends the elements as strings, not as the character type. gettype within the foreach loop shows that I'm sending dealing with the correct types: 16:39:54 SENT 'K' of type string 16:39:54 SENT '0' of type integer 16:39:54 SENT '0' of type integer 16:39:54 SENT '65' of type integer 16:39:54 SENT '31' of type integer fwrite is, according to the documentation, supposed to be binary safe. I think there's a bug in fwrite that has it send all elements as strings. Reproduce code: --------------- function send_back($sock, $msg, $ip, $port) { $fp = fsockopen("udp://$ip", "$port"); foreach ($msg as $msg_to_send) { fwrite($fp, $msg_to_send); echo date("H:i:s")." SENT '$msg_to_send' of type ".gettype($msg_to_send)." \n"; //seen server side } fclose($fp); } Expected result: ---------------- running a packet sniffer, I can see that what's being sent are strings: 15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP | 0000: 4b K 15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP | 0000: 30 0 15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP | 0000: 30 0 15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP | 0000: 3635 65 15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP | 0000: 3331 31 Actual result: -------------- Those last two (65 and 31) should be represented by single bytes, not two bytes. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31090&edit=1