Index: plugins/roard/protocol-esound.c
===================================================================
--- plugins/roard/protocol-esound.c	(revision 2529)
+++ plugins/roard/protocol-esound.c	(revision 2530)
@@ -73,6 +73,10 @@
  int i;
 
+ ROAR_DBG("emul_esd_exec_command(*) = ?");
+
  if ( client == -1 || cmd < ESD_PROTO_CONNECT || cmd > ESD_PROTO_MAX || vio == NULL )
   return -1;
+
+ ROAR_DBG("emul_esd_exec_command(*) = ?");
 
  for (i = 0; (cur = &(g_emul_esd_commands[i]))->cmd != -1; i++) {
Index: roard/include/network.h
===================================================================
--- roard/include/network.h	(revision 668)
+++ roard/include/network.h	(revision 2530)
@@ -30,5 +30,5 @@
 int net_check_listen  (void);
 
-int net_get_new_client (void);
+int net_get_new_client (int sock, int proto);
 
 #endif
Index: roard/include/roard.h
===================================================================
--- roard/include/roard.h	(revision 2519)
+++ roard/include/roard.h	(revision 2530)
@@ -78,4 +78,7 @@
 #define _64BIT 8
 
+// listeing code:
+#define ROAR_MAX_LISTEN_SOCKETS  8
+
 //#include "buffer.h"
 #include "codecfilter.h"
@@ -120,5 +123,6 @@
 
 #ifdef ROAR_SUPPORT_LISTEN
-int g_listen_socket;
+int g_listen_socket[ROAR_MAX_LISTEN_SOCKETS];
+int g_listen_proto[ROAR_MAX_LISTEN_SOCKETS];
 #endif
 
Index: roard/lib.c
===================================================================
--- roard/lib.c	(revision 2500)
+++ roard/lib.c	(revision 2530)
@@ -52,5 +52,7 @@
 
 #ifdef ROAR_SUPPORT_LISTEN
- close(g_listen_socket); // listen socket.
+ for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++)
+  if ( g_listen_socket[i] != -1 )
+   close(g_listen_socket[i]); // listen socket.
 #endif
 
Index: roard/loop.c
===================================================================
--- roard/loop.c	(revision 2500)
+++ roard/loop.c	(revision 2530)
@@ -34,4 +34,8 @@
  float  freq;
 #endif
+#ifdef ROAR_SUPPORT_LISTEN
+ int i;
+ int have_listen;
+#endif
 #ifdef MONITOR_LATENCY
  long int ans_1last = 0, ans_2last = 0, ans_3last = 0;
@@ -59,5 +63,13 @@
 
 #ifdef ROAR_SUPPORT_LISTEN
-  if ( g_listen_socket != -1 ) {
+  have_listen = 0;
+  for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
+   if ( g_listen_socket[i] != -1 ) {
+    have_listen = 1;
+    break;
+   }
+  }
+
+  if ( have_listen ) {
    ROAR_DBG("main_loop(*): check for new clients...");
    net_check_listen();
@@ -67,5 +79,5 @@
   ROAR_DBG("main_loop(*): check for new data...");
 #ifdef ROAR_SUPPORT_LISTEN
-  if ( clients_check_all() == 0 && g_terminate && g_listen_socket == -1 ) {
+  if ( clients_check_all() == 0 && g_terminate && !have_listen ) {
 #else
   if ( clients_check_all() == 0 && g_terminate ) {
Index: roard/network.c
===================================================================
--- roard/network.c	(revision 2529)
+++ roard/network.c	(revision 2530)
@@ -40,14 +40,34 @@
  fd_set sl;
  struct timeval tv;
+ int i;
+ int max_fh = -1;
 
  FD_ZERO(&sl);
- FD_SET(g_listen_socket, &sl);
+
+ for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
+  if ( g_listen_socket[i] != -1 ) {
+   if ( g_listen_socket[i] > max_fh )
+    max_fh = g_listen_socket[i];
+
+   FD_SET(g_listen_socket[i], &sl);
+  }
+ }
+
+ if ( max_fh == -1 )
+  return 0;
 
  tv.tv_sec  = 0;
  tv.tv_usec = 1;
 
- if ((r = select(g_listen_socket + 1, &sl, NULL, NULL, &tv)) > 0) {
+ if ((r = select(max_fh + 1, &sl, NULL, NULL, &tv)) > 0) {
   ROAR_DBG("net_check_listen(void): We have a connection!");
-  return net_get_new_client();
+  for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
+   if ( g_listen_socket[i] != -1 ) {
+    if ( FD_ISSET(g_listen_socket[i], &sl) ) {
+     if ( net_get_new_client(g_listen_socket[i], g_listen_proto[i]) == -1 )
+      return -1;
+    }
+   }
+  }
  }
 
@@ -59,5 +79,5 @@
 
 #ifdef _CAN_OPERATE
-int net_get_new_client (void) {
+int net_get_new_client (int sock, int proto) {
  int fh;
  int client;
@@ -71,5 +91,5 @@
  struct roar_vio_calls vio;
 
- fh = accept(g_listen_socket, NULL, NULL);
+ fh = accept(sock, NULL, NULL);
 
  ROAR_DBG("net_get_new_client(void): fh = %i", fh);
@@ -107,12 +127,18 @@
 #endif
 
- if ( clients_set_proto(client, ROAR_PROTO_ESOUND) == -1 )
+ ROAR_DBG("net_get_new_client(*): proto=0x%.4x", proto);
+
+ if ( clients_set_proto(client, proto) == -1 )
   return -1;
 
- if ( roar_vio_open_fh(&vio, fh) == -1 )
-  return -1;
+ switch (proto) {
+  case ROAR_PROTO_ESOUND:
+    if ( roar_vio_open_fh(&vio, fh) == -1 )
+     return -1;
 
- if ( emul_esd_exec_command(client, ESD_PROTO_CONNECT, &vio) == -1 )
-  return -1;
+    if ( emul_esd_exec_command(client, ESD_PROTO_CONNECT, &vio) == -1 )
+     return -1;
+   break;
+ }
 
 // close(fh);
Index: roard/roard.c
===================================================================
--- roard/roard.c	(revision 2511)
+++ roard/roard.c	(revision 2530)
@@ -26,5 +26,5 @@
 
 #ifdef ROAR_SUPPORT_LISTEN
-char * server = ROAR_DEFAULT_SOCK_GLOBAL; // global server address
+char * server[ROAR_MAX_LISTEN_SOCKETS];
 #endif
 
@@ -32,4 +32,8 @@
 #define SUPPORT_PIDFILE
 char * pidfile = NULL;
+#endif
+
+#if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID)
+ int    setids    = 0;
 #endif
 
@@ -137,4 +141,6 @@
         " -b  --bind            - IP/Hostname to bind to\n"
         "     --sock            - Filename for UNIX Domain Socket\n"
+        "     --proto PROTO     - Use PROTO as protocol on Socket\n"
+        "     --new-sock        - Parameters for new socket follows\n"
 #ifdef ROAR_HAVE_LIBSLP
         "     --slp             - Enable OpenSLP support\n"
@@ -232,4 +238,128 @@
 }
 
+#ifdef ROAR_SUPPORT_LISTEN
+int init_listening (void) {
+ int i;
+
+ for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
+  g_listen_socket[i] = -1;
+  g_listen_proto[i]  = ROAR_PROTO_ROARAUDIO;
+  server[i]          = NULL;
+ }
+
+ return 0;
+}
+
+int get_proto  (char * proto) {
+ if ( !strcasecmp(proto, "roar") ) {
+  return ROAR_PROTO_ROARAUDIO;
+ } else if ( !strcasecmp(proto, "roaraudio") ) {
+  return ROAR_PROTO_ROARAUDIO;
+ } else if ( !strcasecmp(proto, "esd") ) {
+  return ROAR_PROTO_ESOUND;
+ } else if ( !strcasecmp(proto, "esound") ) {
+  return ROAR_PROTO_ESOUND;
+ }
+
+ return -1;
+}
+
+int add_listen (char * addr, int port, int sock_type, char * user, char * group, int proto) {
+#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
+ struct group   * grp  = NULL;
+#endif
+#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
+ struct passwd  * pwd  = NULL;
+#endif
+#ifdef ROAR_HAVE_UNIX
+ char * env_roar_proxy_backup;
+#endif
+ int    sockid = -1;
+ int    sock;
+ int    i;
+
+ if ( *addr != 0 ) {
+  for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
+   if ( g_listen_socket[i] == -1 ) {
+    sockid = i;
+    break;
+   }
+  }
+
+  if ( sockid == -1 )
+   return -1;
+
+  g_listen_proto[sockid] = proto;
+
+  ROAR_DBG("add_listen(*): proto=0x%.4x", proto);
+
+  if ( (g_listen_socket[sockid] = roar_socket_listen(sock_type, addr, port)) == -1 ) {
+#ifdef ROAR_HAVE_UNIX
+   if ( *addr == '/' ) {
+    if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
+     env_roar_proxy_backup = strdup(env_roar_proxy_backup);
+     unsetenv("ROAR_PROXY");
+    }
+    if ( (sock = roar_socket_connect(addr, port)) != -1 ) {
+     close(sock);
+     ROAR_ERR("Can not open listen socket!");
+     return 1;
+    } else {
+     unlink(addr);
+     if ( (g_listen_socket[sockid] = roar_socket_listen(sock_type, addr, port)) == -1 ) {
+      ROAR_ERR("Can not open listen socket!");
+      return 1;
+     }
+    }
+    if ( env_roar_proxy_backup != NULL ) {
+     setenv("ROAR_PROXY", env_roar_proxy_backup, 0);
+     free(env_roar_proxy_backup);
+    }
+#else
+   if (0) { // noop
+#endif
+   } else {
+    ROAR_ERR("Can not open listen socket!");
+    return 1;
+   }
+  }
+
+#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
+  if ( (grp = getgrnam(group)) == NULL ) {
+   ROAR_ERR("Can not get GID for group %s: %s", group, strerror(errno));
+  }
+#endif
+#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
+  if ( user || (setids & R_SETUID) ) {
+   if ( (pwd = getpwnam(user)) == NULL ) {
+    ROAR_ERR("Can not get UID for user %s: %s", user, strerror(errno));
+   }
+  }
+#endif
+
+#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX)
+  if ( *addr == '/' ) {
+   if ( grp ) {
+    if ( pwd ) {
+     if ( chown(addr, pwd->pw_uid, grp->gr_gid) == -1 )
+      return 1;
+    } else {
+     if ( chown(addr, -1, grp->gr_gid) == -1 )
+      return 1;
+    }
+#ifdef ROAR_HAVE_GETUID
+    if ( getuid() == 0 )
+     if ( chmod(addr, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 )
+      return 1;
+#endif
+   }
+  }
+#endif
+ }
+
+ return 0;
+}
+#endif
+
 int update_stream_flags (char * str) {
  int    dir;
@@ -686,5 +816,7 @@
 // char * server = ROAR_DEFAULT_SOCK_GLOBAL;
 #ifdef ROAR_SUPPORT_LISTEN
- int      port    = ROAR_DEFAULT_PORT;
+ int    port       = ROAR_DEFAULT_PORT;
+ char * sock_addr  = NULL;
+ int    sock_proto = ROAR_PROTO_ROARAUDIO;
 #endif
  int               drvid;
@@ -715,10 +847,4 @@
  char * chrootdir = NULL;
 #endif
-#if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID)
- int    setids    = 0;
-#endif
-#ifdef ROAR_HAVE_UNIX
- char * env_roar_proxy_backup;
-#endif
 #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
  struct group   * grp  = NULL;
@@ -744,5 +870,4 @@
 #ifdef ROAR_SUPPORT_LISTEN
  g_no_listen     =  0;
- g_listen_socket = -1;
 #else
  g_terminate     =  1;
@@ -766,4 +891,11 @@
  }
 
+#ifdef ROAR_SUPPORT_LISTEN
+ if ( init_listening() == -1 ) {
+  ROAR_ERR("Can not init listening sockets!");
+  return 1;
+ }
+#endif
+
 #ifndef ROAR_WITHOUT_DCOMP_MIDI
  if ( midi_init_config() == -1 ) {
@@ -781,13 +913,14 @@
 
 #ifdef ROAR_SUPPORT_LISTEN
+ sock_addr = ROAR_DEFAULT_SOCK_GLOBAL;
 #ifdef ROAR_HAVE_GETUID
  if ( getuid() != 0 && getenv("HOME") != NULL ) {
   snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
-  server = user_sock;
+  sock_addr = user_sock;
  }
 #endif
 
  if ( getenv("ROAR_SERVER") != NULL )
-  server = getenv("ROAR_SERVER");
+  sock_addr = getenv("ROAR_SERVER");
 #endif
 
@@ -831,6 +964,6 @@
   } else if ( strcmp(k, "--restart") == 0 ) {
 #ifdef ROAR_SUPPORT_LISTEN
-   if ( restart_server(server, 1) == -1 ) {
-    ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", server);
+   if ( restart_server(sock_addr, 1) == -1 ) {
+    ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", sock_addr);
    }
 #else
@@ -839,6 +972,6 @@
   } else if ( strcmp(k, "--shutdown") == 0 ) {
 #ifdef ROAR_SUPPORT_LISTEN
-   if ( restart_server(server, 1) == -1 ) {
-    ROAR_WARN("Can not terminate old server (not running at %s?)", server);
+   if ( restart_server(sock_addr, 1) == -1 ) {
+    ROAR_WARN("Can not terminate old server (not running at %s?)", sock_addr);
     return 1;
    }
@@ -850,6 +983,6 @@
   } else if ( strcmp(k, "--stop") == 0 ) {
 #ifdef ROAR_SUPPORT_LISTEN
-   if ( restart_server(server, 0) == -1 ) {
-    ROAR_WARN("Can not stop old server (not running at %s?)", server);
+   if ( restart_server(sock_addr, 0) == -1 ) {
+    ROAR_WARN("Can not stop old server (not running at %s?)", sock_addr);
     return 1;
    }
@@ -1042,6 +1175,6 @@
    // This is only usefull in INET not UNIX mode.
 #ifdef ROAR_SUPPORT_LISTEN
-   if ( *server == '/' )
-    server = ROAR_DEFAULT_HOST;
+   if ( *sock_addr == '/' )
+    sock_addr = ROAR_DEFAULT_HOST;
 
    errno = 0;
@@ -1064,5 +1197,13 @@
   } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) {
 #ifdef ROAR_SUPPORT_LISTEN
-   server = argv[++i];
+   sock_addr = argv[++i];
+#endif
+
+  } else if ( strcmp(k, "--proto") == 0 ) {
+#ifdef ROAR_SUPPORT_LISTEN
+   if ( (sock_proto = get_proto(argv[++i])) == -1 ) {
+    ROAR_ERR("Unknown protocol: %s", argv[i]);
+    return 1;
+   }
 #endif
 
@@ -1072,6 +1213,6 @@
     sock_type = ROAR_SOCKET_TYPE_TCP;
 
-   if ( *server == '/' )
-    server = ROAR_DEFAULT_HOST;
+   if ( *sock_addr == '/' )
+    sock_addr = ROAR_DEFAULT_HOST;
 #endif
 
@@ -1079,6 +1220,6 @@
 #ifdef ROAR_SUPPORT_LISTEN
    sock_type = ROAR_SOCKET_TYPE_TCP;
-   if ( *server == '/' )
-    server = ROAR_DEFAULT_HOST;
+   if ( *sock_addr == '/' )
+    sock_addr = ROAR_DEFAULT_HOST;
 #endif
   } else if ( strcmp(k, "-6") == 0 ) {
@@ -1086,6 +1227,6 @@
 #ifdef PF_INET6
    sock_type = ROAR_SOCKET_TYPE_TCP6;
-   if ( *server == '/' )
-    server = ROAR_DEFAULT_HOST;
+   if ( *sock_addr == '/' )
+    sock_addr = ROAR_DEFAULT_HOST;
 #else
     ROAR_ERR("No IPv6 support compiled in!");
@@ -1105,5 +1246,5 @@
     port   = ROAR_DEFAULT_NUM;
     strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT);
-    server = decnethost;
+    sock_addr = decnethost;
     sock_type = ROAR_SOCKET_TYPE_DECNET;
 #else
@@ -1111,4 +1252,11 @@
     return 1;
 #endif
+#endif
+  } else if ( strcmp(k, "--new-sock") == 0 ) {
+#ifdef ROAR_SUPPORT_LISTEN
+   if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto) != 0 ) {
+    ROAR_ERR("Can not open listen socket!");
+    return 1;
+   }
 #endif
 
@@ -1128,5 +1276,5 @@
   } else if ( strcmp(k, "--no-listen") == 0 ) {
 #ifdef ROAR_SUPPORT_LISTEN
-   server      = "";
+   sock_addr   = "";
    g_terminate = 1;
    g_no_listen = 1;
@@ -1188,67 +1336,7 @@
 
 #ifdef ROAR_SUPPORT_LISTEN
- if ( *server != 0 ) {
-  if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) {
-#ifdef ROAR_HAVE_UNIX
-   if ( *server == '/' ) {
-    if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
-     env_roar_proxy_backup = strdup(env_roar_proxy_backup);
-     unsetenv("ROAR_PROXY");
-    }
-    if ( (i = roar_socket_connect(server, port)) != -1 ) {
-     close(i);
-     ROAR_ERR("Can not open listen socket!");
-     return 1;
-    } else {
-     unlink(server);
-     if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) {
-      ROAR_ERR("Can not open listen socket!");
-      return 1;
-     }
-    }
-    if ( env_roar_proxy_backup != NULL ) {
-     setenv("ROAR_PROXY", env_roar_proxy_backup, 0);
-     free(env_roar_proxy_backup);
-    }
-#else
-   if (0) { // noop
-#endif
-   } else {
-    ROAR_ERR("Can not open listen socket!");
-    return 1;
-   }
-  }
-
-#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
-  if ( (grp = getgrnam(sock_grp)) == NULL ) {
-   ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno));
-  }
-#endif
-#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
-  if ( sock_user || (setids & R_SETUID) ) {
-   if ( (pwd = getpwnam(sock_user)) == NULL ) {
-    ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno));
-   }
-  }
-#endif
-
-#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX)
-  if ( *server == '/' ) {
-   if ( grp ) {
-    if ( pwd ) {
-     if ( chown(server, pwd->pw_uid, grp->gr_gid) == -1 )
-      return 1;
-    } else {
-     if ( chown(server, -1, grp->gr_gid) == -1 )
-      return 1;
-    }
-#ifdef ROAR_HAVE_GETUID
-    if ( getuid() == 0 )
-     if ( chmod(server, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 )
-      return 1;
-#endif
-   }
-  }
-#endif
+ if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto) != 0 ) {
+  ROAR_ERR("Can not open listen socket!");
+  return 1;
  }
 #endif
@@ -1389,5 +1477,5 @@
 #ifdef ROAR_HAVE_LIBSLP
  if ( reg_slp ) {
-  register_slp(0, server);
+  register_slp(0, sock_addr);
  }
 #endif
@@ -1405,4 +1493,6 @@
 
 void cleanup_listen_socket (int terminate) {
+ int i;
+
  // Deregister from SLP:
 #ifdef ROAR_HAVE_LIBSLP
@@ -1411,15 +1501,18 @@
 
 #ifdef ROAR_SUPPORT_LISTEN
- if ( g_listen_socket != -1 ) {
+ for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
+  if ( g_listen_socket[i] != -1 ) {
 #ifdef ROAR_HAVE_IO_POSIX
-  close(g_listen_socket);
+   close(g_listen_socket[i]);
 #endif // #else is useless because we are in void context.
 
-  g_listen_socket = -1;
+   g_listen_socket[i] = -1;
 
 #ifdef ROAR_HAVE_UNIX
-  if ( *server == '/' )
-   unlink(server);
-#endif
+   if ( server[i] != NULL )
+    if ( *(server[i]) == '/' )
+     unlink(server[i]);
+#endif
+  }
  }
 
