📄 tcpadv.java
字号:
* set the multicastaddr * * @param multicastaddr set multicastaddr */ public void setMulticastAddr(String multicastaddr) { if (null != multicastaddr) { multicastaddr = multicastaddr.trim(); if (0 == multicastaddr.length()) { multicastaddr = null; } } this.multicastaddr = multicastaddr; } /** * returns the multicastport * * @return string multicastport */ public int getMulticastPort() { return multicastport; } /** * set the multicastport * @param multicastport set multicastport */ public void setMulticastPort(int multicastport) { this.multicastport = multicastport; } /** * returns the multicastsize * * @return integer containting the multicast size */ public int getMulticastSize() { return multicastsize; } /** * set the multicastsize * * @param multicastsize set multicast size */ public void setMulticastSize(int multicastsize) { this.multicastsize = multicastsize; } /** * Returns the public address * * @return string public address */ public String getServer() { return publicAddress; } /** * Set the public address. That is, a the address of a server socket * to connect to from the outside. Argument is in the form host:port * * @param address address */ public void setServer(String address) { if (null != address) { address = address.trim(); if (0 == address.length()) { address = null; } } this.publicAddress = address; } /** * Returns the configuration for outbound connections. * * @return <code>true</code> if outbound connections are allowed otherwise * <code>false</code> */ public boolean isClientEnabled() { return clientEnabled; } /** * Sets the configuration for outbound connections. * * @param enabled <code>true</code> if outbound connections are allowed otherwise * <code>false</code> */ public void setClientEnabled(boolean enabled) { clientEnabled = enabled; } /** * Returns the configuration for inbound connections. * * @return <code>true</code> if inbound connections are allowed otherwise * <code>false</code> */ public boolean isServerEnabled() { return serverEnabled; } /** * Sets the configuration for inbound connections. * * @param enabled <code>true</code> if inbound connections are allowed otherwise * <code>false</code> */ public void setServerEnabled(boolean enabled) { serverEnabled = enabled; } /** * returns the config mode. That is, how the user prefers to configure * the interface address: "auto", "manual" * * @return string config mode */ public String getConfigMode() { return configMode; } /** * set the config mode. That is, how the user prefers to configure * the interface address: "auto", "manual" * * This is just a pure config item. It is never in published advs. The TCP * transport strips it when it initializes. * * @param mode Can be "auto", "manual" other settings will act as the default * which is "auto". */ public void setConfigMode(String mode) { if (!Arrays.asList(CONFIGMODES).contains(mode)) { throw new IllegalArgumentException("Unsupported configuration mode."); } configMode = mode; } /** * Returns the state of whether to only use public address * @return boolean true if set to use "Public Address Only" */ public boolean getPublicAddressOnly() { return publicAddressOnly; } /** * Sets the state of whether to only use public address * @param only true to use "Public Address Only" */ public void setPublicAddressOnly(boolean only) { publicAddressOnly = only; } /** * {@inheritDoc} */ @Override protected boolean handleElement(Element raw) { if (super.handleElement(raw)) { return true; } XMLElement elem = (XMLElement) raw; if (elem.getName().equals(MULTICAST_OFF_TAG)) { setMulticastState(false); return true; } if (elem.getName().equals(ClientOffTag)) { setClientEnabled(false); return true; } if (elem.getName().equals(ServerOffTag)) { setServerEnabled(false); return true; } String value = elem.getTextValue(); if ((null == value) || (0 == value.trim().length())) { return false; } value = value.trim(); if (elem.getName().equals("Protocol")) { setProtocol(value); return true; } if (PORT_ELEMENT.equals(elem.getName())) { try { setPort(Integer.parseInt(value)); Attribute startAttr = elem.getAttribute("start"); Attribute endAttr = elem.getAttribute("end"); if ((null != startAttr) && (null != endAttr)) { setStartPort(Integer.parseInt(startAttr.getValue().trim())); setEndPort(Integer.parseInt(endAttr.getValue().trim())); } } catch (NumberFormatException badPort) { throw new IllegalArgumentException("Illegal port value : " + value); } return true; } if (elem.getName().equals("MulticastAddr")) { setMulticastAddr(value); return true; } if (elem.getName().equals("MulticastPort")) { try { setMulticastPort(Integer.parseInt(value)); } catch (NumberFormatException badPort) { throw new IllegalArgumentException("Illegal multicast port value : " + value); } return true; } if (elem.getName().equals("MulticastSize")) { try { int theMulticastSize = Integer.parseInt(value); setMulticastSize(theMulticastSize); } catch (NumberFormatException badPort) { throw new IllegalArgumentException("Illegal multicast datagram size : " + value); } return true; } if (elem.getName().equals("Server")) { setServer(value); return true; } if (elem.getName().equals("InterfaceAddress")) { setInterfaceAddress(value); return true; } if (elem.getName().equals("ConfigMode")) { setConfigMode(value); return true; } return false; } /** * {@inheritDoc} */ @Override public Document getDocument(MimeMediaType encodeAs) { StructuredDocument adv = (StructuredDocument) super.getDocument(encodeAs); if (!(adv instanceof Attributable)) { throw new IllegalStateException("Only Attributable document types allowed."); } // XXX 20050118 bondolo Some versions apparently don't initialize this field. Eventually make it required. if (null == getProtocol()) { setProtocol("tcp"); } if ((listenPort < -1) || (listenPort > 65535)) { throw new IllegalStateException("Illegal Listen Port Value"); } if ((startPort < -1) || (startPort > 65535)) { throw new IllegalStateException("Illegal Start Port Value"); } if ((endPort < -1) || (endPort > 65535)) { throw new IllegalStateException("Illegal End Port Value"); } if ((0 == startPort) && (endPort != 0) || (0 != startPort) && (endPort == 0)) { throw new IllegalStateException("Port ranges must both be 0 or non-0"); } if ((-1 == startPort) && (endPort != -1) || (-1 != startPort) && (endPort == -1)) { throw new IllegalStateException("Port ranges must both be -1 or not -1"); } if ((null != publicAddress) && ((-1 != startPort) || (listenPort <= 0))) { throw new IllegalStateException("Dynamic ports not supported with public address port forwarding."); } if (getMulticastState() && (null == getMulticastAddr())) { throw new IllegalStateException("Multicast enabled and no address specified."); } if (getMulticastState() && (-1 == getMulticastPort())) { throw new IllegalStateException("Multicast enabled and no port specified."); } if (getMulticastState() && ((getMulticastPort() <= 0) || (getMulticastPort() > 65536))) { throw new IllegalStateException("Illegal Multicast Port Value"); } if (getMulticastState() && (-1 == getMulticastSize())) { throw new IllegalStateException("Multicast enabled and no size specified."); } if (getMulticastState() && ((getMulticastSize() <= 0) || (getMulticastSize() > 1048575L))) { throw new IllegalStateException("Illegal Multicast datagram size"); } if (adv instanceof Attributable) { // Only one flag for now. Easy. if (publicAddressOnly) { ((Attributable) adv).addAttribute(FlagsTag, PublicAddressOnlyAttr); } } Element e11 = adv.createElement("Protocol", getProtocol()); adv.appendChild(e11); if (!isClientEnabled()) { Element e19 = adv.createElement(ClientOffTag); adv.appendChild(e19); } if (!isServerEnabled()) { Element e20 = adv.createElement(ServerOffTag); adv.appendChild(e20); } if (getConfigMode() != null) { Element e18 = adv.createElement("ConfigMode", getConfigMode()); adv.appendChild(e18); } String interfaceAddr = getInterfaceAddress(); if (null != interfaceAddr) { Element e17 = adv.createElement("InterfaceAddress", interfaceAddr); adv.appendChild(e17); } Element e12 = adv.createElement(PORT_ELEMENT, Integer.toString(listenPort)); adv.appendChild(e12); if (adv instanceof Attributable) { Attributable attrElem = (Attributable) e12; if ((-1 != startPort) && (-1 != endPort)) { attrElem.addAttribute("start", Integer.toString(startPort)); attrElem.addAttribute("end", Integer.toString(endPort)); } } String serverAddr = getServer(); if (null != serverAddr) { Element e16 = adv.createElement("Server", serverAddr); adv.appendChild(e16); } if (!getMulticastState()) { Element e19 = adv.createElement(MULTICAST_OFF_TAG); adv.appendChild(e19); } if (null != getMulticastAddr()) { Element e13 = adv.createElement("MulticastAddr", getMulticastAddr()); adv.appendChild(e13); } if (-1 != getMulticastPort()) { Element e14 = adv.createElement("MulticastPort", Integer.toString(getMulticastPort())); adv.appendChild(e14); } if (-1 != getMulticastSize()) { Element e15 = adv.createElement("MulticastSize", Integer.toString(getMulticastSize())); adv.appendChild(e15); } return adv; } /** * {@inheritDoc} */ @Override public String[] getIndexFields() { return INDEXFIELDS; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -