wsky / top-push

Message-push abstraction component, provide useful messaging components.
8 stars 4 forks source link

send exception message and error code when closing connection #8

Closed wsky closed 11 years ago

wsky commented 11 years ago

websocket status code usage?

what kind of exception should tell client:

wsky commented 11 years ago

close with status code http://msdn.microsoft.com/zh-cn/library/system.net.httpstatuscode.aspx

int statusCode = this.clientConnection.verifyHeaders();
        if (statusCode != 101) {
            this.release();
            frameConnection.close(statusCode, "invalid header");
            return;
        }
        if (this.manager.isReachMaxConnectionCount()) {
            this.release();
            frameConnection.close(400, "reach max connections");
            return;
        }
try {
            Message msg = this.clientConnection.parse(data, offset, length);
            // deliver to target client
            this.manager.getClient(msg.to).pendingMessage(msg);
        } catch (MessageTooLongException e) {
            e.printStackTrace();
            this.frameConnection.close(400, e.getMessage());
        } catch (MessageTypeNotSupportException e) {
            e.printStackTrace();
            this.frameConnection.close(400, e.getMessage());
        } catch (NoMessageBufferException e) {
            e.printStackTrace();
            this.frameConnection.close(400, e.getMessage());
        }