Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## in init() method
- <?php
- // Initialise remote listener
- if(!$this->socket_server)
- {
- $socket = stream_socket_server("udp://0.0.0.0:1337", $errno, $errstr, STREAM_SERVER_BIND);
- if(!$socket)
- {
- $this->send_msg('failed to open socket!');
- }
- else
- {
- $this->socket_server = $socket;
- }
- }
- ## in poll() method (called on each loop of the irc bot)
- <?php
- // Process incoming stream requests
- if($this->socket_server)
- {
- // Setup arrays for stream_select
- $read = array($this->socket_server);
- $write = NULL;
- $except = NULL;
- // Check if we have data to read
- while(stream_select($read, $write, $except, 0, 0))
- {
- // Read the data from the UDP socket
- $line = fgets($this->socket_server, 4096);
- // Forward the message to the channel
- $this->send_msg($line);
- }
- }
- ## Client webserver script
- <?php
- $fp = stream_socket_client("udp://:1337", $errno, $errstr);
- if (!$fp) {
- echo "ERROR: $errno - $errstr<br />\n";
- } else {
- fwrite($fp, "Hello, World!\r\n");
- fclose($fp);
- }
- ?>
Add Comment
Please, Sign In to add comment