Index: /branches/eam_branches/ipp-20140423/Ohana/src/kapa2/src/CheckPipe.c
===================================================================
--- /branches/eam_branches/ipp-20140423/Ohana/src/kapa2/src/CheckPipe.c	(revision 36739)
+++ /branches/eam_branches/ipp-20140423/Ohana/src/kapa2/src/CheckPipe.c	(revision 36740)
@@ -1,3 +1,4 @@
 # include "Ximage.h"
+# include <errno.h>
 # define STRCONST(A) ((int)(0x1000000*A[0] + 0x10000*A[1] + 0x100*A[2] + 0x1*A[3]))
 
@@ -41,6 +42,11 @@
   word[4] = 0;
   switch (status) {
-  case -1:                          /* no input from pipe: continue */
-    return (TRUE);
+  case -1:
+    if (errno == EAGAIN) {
+      /* no input from pipe: continue */
+      return (TRUE);
+    } 
+    perror ("exiting due to problem with socket connection in CheckPipe");
+    return (FALSE);
     break;
 
Index: /branches/eam_branches/ipp-20140423/Ohana/src/libkapa/src/KapaOpen.c
===================================================================
--- /branches/eam_branches/ipp-20140423/Ohana/src/libkapa/src/KapaOpen.c	(revision 36739)
+++ /branches/eam_branches/ipp-20140423/Ohana/src/libkapa/src/KapaOpen.c	(revision 36740)
@@ -218,15 +218,32 @@
   // apparently, I can connect on someone else's port (eg GoogleTalkPlugin)
   // do a simple handshake before we set !NONBLOCK:
-  char line[5];
-  int Nout = read (InitSocket, line, 4);
-  if (Nout != 4) {
-    if (DEBUG) fprintf (stderr, "connection failed\n");
-    close (InitSocket);
-    return (-1);
-  }
-  if (strncmp (line, "KAPA", 4)) {
-    if (DEBUG) fprintf (stderr, "connection to the wrong server\n");
-    close (InitSocket);
-    return (-1);
+
+  // ensure the socket is NONBLOCK first...
+  fcntl (InitSocket, F_SETFL, O_NONBLOCK);
+
+  int Ntry = 0;
+retry_message:
+  { 
+    char line[5];
+    int Nout = read (InitSocket, line, 4);
+    if ((Nout == -1) && (errno == EAGAIN)) {
+      Ntry ++;
+      if (Ntry > 500) {
+	if (DEBUG) fprintf (stderr, "handshake failure\n");
+	close (InitSocket);
+	return (-1);
+      }
+      goto retry_message;
+    }
+    if (Nout != 4) {
+      if (DEBUG) fprintf (stderr, "connection failed\n");
+      close (InitSocket);
+      return (-1);
+    }
+    if (strncmp (line, "KAPA", 4)) {
+      if (DEBUG) fprintf (stderr, "connection to the wrong server\n");
+      close (InitSocket);
+      return (-1);
+    }
   }
 
