diff --git a/Foundation Web Core/src/com/foundation/web/server/SocketContext.java b/Foundation Web Core/src/com/foundation/web/server/SocketContext.java index 4fd6a3e..a807852 100644 --- a/Foundation Web Core/src/com/foundation/web/server/SocketContext.java +++ b/Foundation Web Core/src/com/foundation/web/server/SocketContext.java @@ -726,26 +726,32 @@ private void loadNextWebsocketMessage() { * @return */ private synchronized void internalProcessResponses() { - boolean finishedSending = true; + boolean doneSending = false; //Keep sending responses while the buffers are not full and there is another response to send.// - while(finishedSending) { + while(!doneSending) { + boolean messageSent = true; + //If the socket is open then send the next buffer of data.// if(key.channel().isOpen()) { //Send the pending response object's prepared buffer of data.// - finishedSending = writeClientBoundMessage(); + messageSent = writeClientBoundMessage(); }//if// //Close the response if successfully sent, or if the socket is closed.// - if(finishedSending || !key.channel().isOpen()) { + if((messageSent || !key.channel().isOpen()) && currentOutboundMessage != null) { try {currentOutboundMessage.close();} catch(Throwable e) {} }//if// //If we finished sending the current response then load the next one.// - if(finishedSending) { + if(messageSent) { //TODO: Queue up the next outbound message. currentOutboundMessage = null; }//if// + + if(currentOutboundMessage == null) { + doneSending = true; + }//if// }//while// // //Keep sending responses while the buffers are not full and there is another response to send.//