diff --git a/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php b/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php
index 23f86a4d450742bb967cd04b224087582ddf1fb6..9e83eadb801d0ed5dd80f80b28f17c26dff5ad5b 100755
--- a/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php
+++ b/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php
@@ -1159,7 +1159,7 @@ class TgExtra {
         $arrResource = $this->connection['resource']->search( $this->rbac->getConfiguration()->getValue( "resource", "base" ), $filter, "sub" );
 
 
-         if( sizeof( $arrResource ) == 1 ) {
+        if( sizeof( $arrResource ) == 1 ) {
 
           $result->result = $this->connection['resource']->delete( $arrResource[0]['dn'] );
 
@@ -1221,6 +1221,7 @@ class TgExtra {
     $registerTry = 10;                // The number of tries of registering the resource
     $resourceNamingAttribute = "";    // The naming-attribute of the resource
     $arrCounter = false;              // The counter entry
+    $askedDaemon = false;
     $result = new booleanResponse();  // The return-result
 
 
@@ -1229,35 +1230,60 @@ class TgExtra {
       // The TextGrid-resource naming-attribute
       $resourceNamingAttribute = $this->rbac->getConfiguration()->getValue( "resource", "namingattribute" );
 
+      $sock = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
 
-      // Look for the counter entry for resources.
-      $arrCounter = $this->connection['counter']->getEntry( "cn=resource," . $this->config->getValue( "counter", "base" ) );
+      if( socket_connect( $sock, '127.0.0.1', 6645 ) ) {
 
+    //  socket_write( $sock, $arrQuery, strlen( $arrQuery ) );
+    //  socket_write( $sock, "\r\n", strlen( "\r\n" ) );
 
-      // If there is a counter entry, use it
-      if( isset( $arrCounter['dn'] ) ) {
 
-        $freeNumber = $arrCounter['sn'][0] + 1;
+        $freeNumber = socket_read( $sock, 1024 );
+
+        if( $freeNumber > 0 ) {
+
+          $askedDaemon = true;
+          $registerTry = 1;
+
+        }
+
+
+        socket_shutdown( $sock, 2 );
+        socket_close( $sock );
 
       }
       else {
 
-        $arrResourceName = $this->connection['resource']->search( $this->config->getValue( "textGridResource", "base" ),
-                                                                  "(objectClass=textGridResource)",
-                                                                  "one", $resourceNamingAttribute );
+        // Look for the counter entry for resources.
+        $arrCounter = $this->connection['counter']->getEntry( "cn=resource," . $this->config->getValue( "counter", "base" ) );
 
 
-        // Every returned resource has to be examined for
-        // its number to get the next free one.
-        for( $i = 0; $i < sizeof( $arrResourceName ); $i++ ) {
+        // If there is a counter entry, use it
+        if( isset( $arrCounter['dn'] ) ) {
 
-          $resourceName = preg_replace( "/^TGRS/i", "", $arrResourceName[$i][$resourceNamingAttribute][0] );
-          $maxNumber = max( $maxNumber, intval( $resourceName ) );
+          $freeNumber = $arrCounter['sn'][0] + 1;
 
         }
+        else {
+
+          $arrResourceName = $this->connection['resource']->search( $this->config->getValue( "textGridResource", "base" ),
+                                                                    "(objectClass=textGridResource)",
+                                                                    "one", $resourceNamingAttribute );
+
+
+          // Every returned resource has to be examined for
+          // its number to get the next free one.
+          for( $i = 0; $i < sizeof( $arrResourceName ); $i++ ) {
+
+            $resourceName = preg_replace( "/^TGRS/i", "", $arrResourceName[$i][$resourceNamingAttribute][0] );
+            $maxNumber = max( $maxNumber, intval( $resourceName ) );
 
+          }
+
+
+          $freeNumber = $maxNumber + 1;
 
-        $freeNumber = $maxNumber + 1;
+        }
 
       }
 
@@ -1322,22 +1348,26 @@ class TgExtra {
         }
 
 
-        // This entry will add or modify the directory that way
-        // that there is a counter entry.
-        $arrEntry = Array();
-        $arrEntry['objectclass'][] = "person";
-        $arrEntry['cn'][] = "resource";
-        $arrEntry['sn'][] = $freeNumber;
+        if( !$askedDaemon ) {
 
+          // This entry will add or modify the directory that way
+          // that there is a counter entry.
+          $arrEntry = Array();
+          $arrEntry['objectclass'][] = "person";
+          $arrEntry['cn'][] = "resource";
+          $arrEntry['sn'][] = $freeNumber;
 
-        if( !isset( $arrCounter['dn'] ) ) {
 
-          $this->connection['counter']->add( "cn=resource," . $this->config->getValue( "counter", "base" ), $arrEntry );
+          if( !isset( $arrCounter['dn'] ) ) {
 
-        }
-        else {
+            $this->connection['counter']->add( "cn=resource," . $this->config->getValue( "counter", "base" ), $arrEntry );
+
+          }
+          else {
 
-          $this->connection['counter']->modify( "cn=resource," . $this->config->getValue( "counter", "base" ), $arrEntry );
+            $this->connection['counter']->modify( "cn=resource," . $this->config->getValue( "counter", "base" ), $arrEntry );
+
+          }
 
         }