Re: UDP Packet Writing

From: Date: Thu, 08 May 2003 14:44:49 +0000
Subject: Re: UDP Packet Writing
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-146848@lists.php.net to get a copy of this message
"Adam Voigt" <adam@cryptocomm.com> wrote in message news:1052402541.2449.25.camel@beowulf.cryptocomm.com... > I'm trying to interface with a hardware device, and > according to the networking API for it, in order > to communicate with it, you need to send UDP packets > crafted in a certain format. Example: > > 0 Command Routine > 1 reserved > 2..5 IP to Sync > 6..7 Port > 8..17 reserved > > > And well I'm not quite sure how to do this. > Am I jus supposed to use the socket functions to > open a connection, then write it all with one > fwrite, implaning a NULL where it says reserved, > or what? <?php function SendUdpMsg($host, $port, $msg) { $udp = fsockopen("udp://$host", $port); fwrite($udp, $msg); fclose($udp); } function CommandStr($cmd, $ip, $port) { return pack( "CCLSC*", $cmd, 0, $ip, $port, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); } SendUDPMsg( "127.0.0.1", 8001, CommandStr(3, ip2long("127.0.0.1"), 8002) ); ?>

« previous php.general (#146848) next »