Index: trunk/BNC/bncapp.cpp
===================================================================
--- trunk/BNC/bncapp.cpp	(revision 641)
+++ trunk/BNC/bncapp.cpp	(revision 642)
@@ -43,4 +43,5 @@
 #include <QMessageBox>
 #include <cmath>
+#include <unistd.h>
 
 #include "bncapp.h" 
@@ -524,9 +525,17 @@
   // ----------------------
   if (_sockets) {
-    QListIterator<QTcpSocket*> is(*_sockets);
+    QMutableListIterator<QTcpSocket*> is(*_sockets);
     while (is.hasNext()) {
       QTcpSocket* sock = is.next();
       if (sock->state() == QAbstractSocket::ConnectedState) {
-        sock->write(allLines);
+        int fd = sock->socketDescriptor();
+        if (::write(fd, allLines.data(), allLines.size()) != allLines.size()) {
+          delete sock;
+          is.remove();
+        }
+      }
+      else if (sock->state() != QAbstractSocket::ConnectingState) {
+        delete sock;
+        is.remove();
       }
     }
@@ -590,9 +599,17 @@
   // ----------------------
   if (_sockets) {
-    QListIterator<QTcpSocket*> is(*_sockets);
+    QMutableListIterator<QTcpSocket*> is(*_sockets);
     while (is.hasNext()) {
       QTcpSocket* sock = is.next();
       if (sock->state() == QAbstractSocket::ConnectedState) {
-        sock->write(allLines);
+        int fd = sock->socketDescriptor();
+        if (::write(fd, allLines.data(), allLines.size()) != allLines.size()) {
+          delete sock;
+          is.remove();
+        }
+      }
+      else if (sock->state() != QAbstractSocket::ConnectingState) {
+        delete sock;
+        is.remove();
       }
     }
