diff --git a/src/net/tootallnate/websocket/WebSocketServer.java b/src/net/tootallnate/websocket/WebSocketServer.java
index <HASH>..<HASH> 100644
--- a/src/net/tootallnate/websocket/WebSocketServer.java
+++ b/src/net/tootallnate/websocket/WebSocketServer.java
@@ -218,7 +218,7 @@ public abstract class WebSocketServer implements Runnable, WebSocketListener {
 
           // if isWritable == true
           // then we need to send the rest of the data to the client
-          if (key.isWritable()) {
+          if (key.isValid() && key.isWritable()) {
             WebSocket conn = (WebSocket)key.attachment();
             if (conn.handleWrite()) {
               conn.socketChannel().register(selector,
Fixed an issue with WebSocketServer that was causing a CancelledKeyException to be thrown when a client disconnected.