keepAlive for SocketExceptions (#58)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 56bae68..379eaf6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
 ## 4.1.1-dev
 
+- Apply `keepAlive` logic to `SocketException`s.
+
 ## 4.1.0
 
 - Limit the number of concurrent requests to prevent Chrome from automatically
diff --git a/lib/src/server/sse_handler.dart b/lib/src/server/sse_handler.dart
index 8a5db5c..72cc919 100644
--- a/lib/src/server/sse_handler.dart
+++ b/lib/src/server/sse_handler.dart
@@ -4,6 +4,7 @@
 
 import 'dart:async';
 import 'dart:convert';
+import 'dart:io';
 
 import 'package:async/async.dart';
 import 'package:collection/collection.dart';
@@ -97,14 +98,16 @@
         _sink.add('data: ${json.encode(data)}\n');
         _sink.add('\n');
         await _outgoingStreamQueue.next; // Consume from stream if no errors.
-      } on StateError catch (_) {
-        if (_keepAlive == null || _closedCompleter.isCompleted) {
+      } catch (e) {
+        if ((e is StateError || e is SocketException) &&
+            (_keepAlive != null && !_closedCompleter.isCompleted)) {
+          // If we got here then the sink may have closed but the stream.onDone
+          // hasn't fired yet, so pause the subscription and skip calling
+          // `next` so the message remains in the queue to try again.
+          _handleDisconnect();
+        } else {
           rethrow;
         }
-        // If we got here then the sink may have closed but the stream.onDone
-        // hasn't fired yet, so pause the subscription and skip calling
-        // `next` so the message remains in the queue to try again.
-        _handleDisconnect();
       }
     }
   }