]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/listener/udp/class_UdpListener.php
Renamed FooNetworkPackageHandler to FooRawDataHandler, because it handles raw data...
[hub.git] / application / hub / main / listener / udp / class_UdpListener.php
index df27bf096ad8a866214e5b0c4e22027355768489..4e8c52b6a777924218e9a7d493d31bf90608efa3 100644 (file)
@@ -30,6 +30,9 @@ class UdpListener extends BaseListener implements Listenable {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
+
+               // Set the protocol to UDP
+               $this->setProtocol('udp');
        }
 
        /**
@@ -45,9 +48,6 @@ class UdpListener extends BaseListener implements Listenable {
                // Set the application instance
                $listenerInstance->setNodeInstance($nodeInstance);
 
-               // Set the protocol to UDP
-               $listenerInstance->setProtocol('udp');
-
                // Return the prepared instance
                return $listenerInstance;
        }
@@ -70,7 +70,7 @@ class UdpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Set the option to reuse the port
-               $this->debugOutput('LISTENER: Setting re-use address option.');
+               $this->debugOutput('UDP-LISTENER: Setting re-use address option.');
                if (!socket_set_option($mainSocket, SOL_SOCKET, SO_REUSEADDR, 1)) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -88,7 +88,7 @@ class UdpListener extends BaseListener implements Listenable {
                // "Bind" the socket to the given address, on given port so this means
                // that all connections on this port are now our resposibility to
                // send/recv data, disconnect, etc..
-               $this->debugOutput('LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
+               $this->debugOutput('UDP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
                if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -104,7 +104,7 @@ class UdpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Now, we want non-blocking mode
-               $this->debugOutput('LISTENER: Setting non-blocking mode.');
+               $this->debugOutput('UDP-LISTENER: Setting non-blocking mode.');
                if (!socket_set_nonblock($mainSocket)) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($socket);
@@ -122,8 +122,14 @@ class UdpListener extends BaseListener implements Listenable {
                // Remember the socket in our class
                $this->registerServerSocketResource($mainSocket);
 
+               // Initialize the network package handler
+               $handlerInstance = ObjectFactory::createObjectByConfiguredName('udp_raw_data_handler_class');
+
+               // Set it in this class
+               $this->setHandlerInstance($handlerInstance);
+
                // Output message
-               $this->debugOutput('LISTENER: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
+               $this->debugOutput('UDP-LISTENER: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
        }
 
        /**
@@ -153,7 +159,7 @@ class UdpListener extends BaseListener implements Listenable {
                        return;
                } elseif ($lastError > 0) {
                        // Other error detected
-                       $this->debugOutput('LISTENER: Error detected: ' . socket_strerror($lastError));
+                       $this->debugOutput('UDP-LISTENER: Error detected: ' . socket_strerror($lastError));
 
                        // Skip further processing
                        return;
@@ -163,7 +169,7 @@ class UdpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Debug only
-               $this->debugOutput('LISTENER: Handling UDP package with size ' . strlen($pkt) . ' from peer ' . $peer . ':' . $port);
+               $this->debugOutput('UDP-LISTENER: Handling UDP package with size ' . strlen($pkt) . ' from peer ' . $peer . ':' . $port);
        }
 
        /**