public synchronized SessionEndpoint createSession(String name) { // todo assert connection state SessionEndpoint endpoint = new SessionEndpoint(this); short channel = getFirstFreeChannel(); if (channel != -1) { _sendingSessions[channel] = endpoint; endpoint.setSendingChannel(channel); Begin begin = new Begin(); begin.setNextOutgoingId(endpoint.getNextOutgoingId()); begin.setOutgoingWindow(endpoint.getOutgoingWindowSize()); begin.setIncomingWindow(endpoint.getIncomingWindowSize()); begin.setHandleMax(_handleMax); send(channel, begin); } else { // todo error } return endpoint; }