private void close(int code, String message, boolean remote) { if (readystate != READYSTATE.CLOSING && readystate != READYSTATE.CLOSED) { if (readystate == READYSTATE.OPEN) { if (code == CloseFrame.ABNORMAL_CLOSE) { assert (remote == false); readystate = READYSTATE.CLOSING; flushAndClose(code, message, false); return; } if (draft.getCloseHandshakeType() != CloseHandshakeType.NONE) { try { if (!remote) { try { wsl.onWebsocketCloseInitiated(this, code, message); } catch (RuntimeException e) { wsl.onWebsocketError(this, e); } } sendFrame(new CloseFrameBuilder(code, message)); } catch (InvalidDataException e) { wsl.onWebsocketError(this, e); flushAndClose(CloseFrame.ABNORMAL_CLOSE, "generated frame is invalid", false); } } flushAndClose(code, message, remote); } else if (code == CloseFrame.FLASHPOLICY) { assert (remote); flushAndClose(CloseFrame.FLASHPOLICY, message, true); } else { flushAndClose(CloseFrame.NEVER_CONNECTED, message, false); } if (code == CloseFrame.PROTOCOL_ERROR) // this endpoint found a PROTOCOL_ERROR flushAndClose(code, message, remote); readystate = READYSTATE.CLOSING; tmpHandshakeBytes = null; return; } }
private void send(Collection<Framedata> frames) { if (!isOpen()) throw new WebsocketNotConnectedException(); for (Framedata f : frames) { sendFrame(f); } }