一、前言
关于apache的commons-net包基于java.net.Socket的org.apache.commons.net.telnet.Telnet功能,具体源码说明
二、源码说明
1.Telnet类
package org.apache.commons.net.telnet;@b@@b@import java.io.BufferedInputStream;@b@import java.io.BufferedOutputStream;@b@import java.io.IOException;@b@import java.io.OutputStream;@b@import org.apache.commons.net.SocketClient;@b@@b@class Telnet extends SocketClient@b@{@b@ static final boolean debug = 0;@b@ static final boolean debugoptions = 0;@b@ static final byte[] _COMMAND_DO = { -1, -3 };@b@ static final byte[] _COMMAND_DONT = { -1, -2 };@b@ static final byte[] _COMMAND_WILL = { -1, -5 };@b@ static final byte[] _COMMAND_WONT = { -1, -4 };@b@ static final byte[] _COMMAND_SB = { -1, -6 };@b@ static final byte[] _COMMAND_SE = { -1, -16 };@b@ static final int _WILL_MASK = 1;@b@ static final int _DO_MASK = 2;@b@ static final int _REQUESTED_WILL_MASK = 4;@b@ static final int _REQUESTED_DO_MASK = 8;@b@ static final int DEFAULT_PORT = 23;@b@ int[] _doResponse;@b@ int[] _willResponse;@b@ int[] _options;@b@ protected static final int TERMINAL_TYPE = 24;@b@ protected static final int TERMINAL_TYPE_SEND = 1;@b@ protected static final int TERMINAL_TYPE_IS = 0;@b@ static final byte[] _COMMAND_IS = { 24, 0 };@b@ private String terminalType = null;@b@ private TelnetOptionHandler[] optionHandlers;@b@ static final byte[] _COMMAND_AYT = { -1, -10 };@b@ private Object aytMonitor = new Object();@b@ private volatile boolean aytFlag = true;@b@ private volatile OutputStream spyStream = null;@b@ private TelnetNotificationHandler __notifhand = null;@b@@b@ Telnet()@b@ {@b@ setDefaultPort(23);@b@ this._doResponse = new int[256];@b@ this._willResponse = new int[256];@b@ this._options = new int[256];@b@ this.optionHandlers = new TelnetOptionHandler[256];@b@ }@b@@b@ Telnet(String termtype)@b@ {@b@ setDefaultPort(23);@b@ this._doResponse = new int[256];@b@ this._willResponse = new int[256];@b@ this._options = new int[256];@b@ this.terminalType = termtype;@b@ this.optionHandlers = new TelnetOptionHandler[256];@b@ }@b@@b@ boolean _stateIsWill(int option)@b@ {@b@ return ((this._options[option] & 0x1) != 0);@b@ }@b@@b@ boolean _stateIsWont(int option)@b@ {@b@ return (!(_stateIsWill(option)));@b@ }@b@@b@ boolean _stateIsDo(int option)@b@ {@b@ return ((this._options[option] & 0x2) != 0);@b@ }@b@@b@ boolean _stateIsDont(int option)@b@ {@b@ return (!(_stateIsDo(option)));@b@ }@b@@b@ boolean _requestedWill(int option)@b@ {@b@ return ((this._options[option] & 0x4) != 0);@b@ }@b@@b@ boolean _requestedWont(int option)@b@ {@b@ return (!(_requestedWill(option)));@b@ }@b@@b@ boolean _requestedDo(int option)@b@ {@b@ return ((this._options[option] & 0x8) != 0);@b@ }@b@@b@ boolean _requestedDont(int option)@b@ {@b@ return (!(_requestedDo(option)));@b@ }@b@@b@ void _setWill(int option)@b@ throws IOException@b@ {@b@ this._options[option] |= 1;@b@@b@ if ((_requestedWill(option)) && @b@ (this.optionHandlers[option] != null))@b@ {@b@ this.optionHandlers[option].setWill(true);@b@@b@ int[] subneg = this.optionHandlers[option].startSubnegotiationLocal();@b@@b@ if (subneg != null)@b@ {@b@ _sendSubnegotiation(subneg);@b@ }@b@ }@b@ }@b@@b@ void _setDo(int option)@b@ throws IOException@b@ {@b@ this._options[option] |= 2;@b@@b@ if ((_requestedDo(option)) && @b@ (this.optionHandlers[option] != null))@b@ {@b@ this.optionHandlers[option].setDo(true);@b@@b@ int[] subneg = this.optionHandlers[option].startSubnegotiationRemote();@b@@b@ if (subneg != null)@b@ {@b@ _sendSubnegotiation(subneg);@b@ }@b@ }@b@ }@b@@b@ void _setWantWill(int option)@b@ {@b@ this._options[option] |= 4;@b@ }@b@@b@ void _setWantDo(int option)@b@ {@b@ this._options[option] |= 8;@b@ }@b@@b@ void _setWont(int option)@b@ {@b@ this._options[option] &= -2;@b@@b@ if (this.optionHandlers[option] != null)@b@ {@b@ this.optionHandlers[option].setWill(false);@b@ }@b@ }@b@@b@ void _setDont(int option)@b@ {@b@ this._options[option] &= -3;@b@@b@ if (this.optionHandlers[option] != null)@b@ {@b@ this.optionHandlers[option].setDo(false);@b@ }@b@ }@b@@b@ void _setWantWont(int option)@b@ {@b@ this._options[option] &= -5;@b@ }@b@@b@ void _setWantDont(int option)@b@ {@b@ this._options[option] &= -9;@b@ }@b@@b@ void _processCommand(int command)@b@ {@b@ if (this.__notifhand != null)@b@ {@b@ this.__notifhand.receivedNegotiation(5, command);@b@ }@b@ }@b@@b@ void _processDo(int option)@b@ throws IOException@b@ {@b@ if (this.__notifhand != null)@b@ {@b@ this.__notifhand.receivedNegotiation(1, option);@b@ }@b@@b@ boolean acceptNewState = false;@b@@b@ if (this.optionHandlers[option] != null)@b@ {@b@ acceptNewState = this.optionHandlers[option].getAcceptLocal();@b@ }@b@ else if ((option == 24) && @b@ (this.terminalType != null) && (this.terminalType.length() > 0))@b@ {@b@ acceptNewState = true;@b@ }@b@@b@ if (this._willResponse[option] > 0)@b@ {@b@ this._willResponse[option] -= 1;@b@ if ((this._willResponse[option] > 0) && (_stateIsWill(option)))@b@ {@b@ this._willResponse[option] -= 1;@b@ }@b@ }@b@@b@ if (this._willResponse[option] == 0)@b@ {@b@ if (_requestedWont(option))@b@ {@b@ switch (option)@b@ {@b@ }@b@@b@ if (acceptNewState)@b@ {@b@ _setWantWill(option);@b@ _sendWill(option);@b@ }@b@ else@b@ {@b@ this._willResponse[option] += 1;@b@ _sendWont(option);@b@ }@b@@b@ }@b@ else@b@ {@b@ switch (option)@b@ {@b@ }@b@@b@ }@b@@b@ }@b@@b@ _setWill(option);@b@ }@b@@b@ void _processDont(int option)@b@ throws IOException@b@ {@b@ if (this.__notifhand != null)@b@ {@b@ this.__notifhand.receivedNegotiation(2, option);@b@ }@b@@b@ if (this._willResponse[option] > 0)@b@ {@b@ this._willResponse[option] -= 1;@b@ if ((this._willResponse[option] > 0) && (_stateIsWont(option)))@b@ {@b@ this._willResponse[option] -= 1;@b@ }@b@ }@b@@b@ if ((this._willResponse[option] == 0) && (_requestedWill(option)))@b@ {@b@ switch (option)@b@ {@b@ }@b@@b@ if ((_stateIsWill(option)) || (_requestedWill(option)))@b@ {@b@ _sendWont(option);@b@ }@b@@b@ _setWantWont(option);@b@ }@b@@b@ _setWont(option);@b@ }@b@@b@ void _processWill(int option)@b@ throws IOException@b@ {@b@ if (this.__notifhand != null)@b@ {@b@ this.__notifhand.receivedNegotiation(3, option);@b@ }@b@@b@ boolean acceptNewState = false;@b@@b@ if (this.optionHandlers[option] != null)@b@ {@b@ acceptNewState = this.optionHandlers[option].getAcceptRemote();@b@ }@b@@b@ if (this._doResponse[option] > 0)@b@ {@b@ this._doResponse[option] -= 1;@b@ if ((this._doResponse[option] > 0) && (_stateIsDo(option)))@b@ {@b@ this._doResponse[option] -= 1;@b@ }@b@ }@b@@b@ if ((this._doResponse[option] == 0) && (_requestedDont(option)))@b@ {@b@ switch (option)@b@ {@b@ }@b@@b@ if (acceptNewState)@b@ {@b@ _setWantDo(option);@b@ _sendDo(option);@b@ }@b@ else@b@ {@b@ this._doResponse[option] += 1;@b@ _sendDont(option);@b@ }@b@ }@b@@b@ _setDo(option);@b@ }@b@@b@ void _processWont(int option)@b@ throws IOException@b@ {@b@ if (this.__notifhand != null)@b@ {@b@ this.__notifhand.receivedNegotiation(4, option);@b@ }@b@@b@ if (this._doResponse[option] > 0)@b@ {@b@ this._doResponse[option] -= 1;@b@ if ((this._doResponse[option] > 0) && (_stateIsDont(option)))@b@ {@b@ this._doResponse[option] -= 1;@b@ }@b@ }@b@@b@ if ((this._doResponse[option] == 0) && (_requestedDo(option)))@b@ {@b@ switch (option)@b@ {@b@ }@b@@b@ if ((_stateIsDo(option)) || (_requestedDo(option)))@b@ {@b@ _sendDont(option);@b@ }@b@@b@ _setWantDont(option);@b@ }@b@@b@ _setDont(option);@b@ }@b@@b@ void _processSuboption(int[] suboption, int suboptionLength)@b@ throws IOException@b@ {@b@ if (suboptionLength > 0)@b@ {@b@ if (this.optionHandlers[suboption[0]] != null)@b@ {@b@ int[] responseSuboption = this.optionHandlers[suboption[0]].answerSubnegotiation(suboption, suboptionLength);@b@@b@ _sendSubnegotiation(responseSuboption);@b@ }@b@ else if ((suboptionLength > 1) && @b@ (suboption[0] == 24) && (suboption[1] == 1))@b@ {@b@ _sendTerminalType();@b@ }@b@ }@b@ }@b@@b@ final synchronized void _sendTerminalType()@b@ throws IOException@b@ {@b@ if (this.terminalType != null)@b@ {@b@ this._output_.write(_COMMAND_SB);@b@ this._output_.write(_COMMAND_IS);@b@ this._output_.write(this.terminalType.getBytes());@b@ this._output_.write(_COMMAND_SE);@b@ this._output_.flush();@b@ }@b@ }@b@@b@ final synchronized void _sendSubnegotiation(int[] subn)@b@ throws IOException@b@ {@b@ if (subn != null)@b@ {@b@ this._output_.write(_COMMAND_SB);@b@@b@ for (int ii = 0; ii < subn.length; ++ii)@b@ {@b@ byte b = (byte)subn[ii];@b@ if (b == -1)@b@ this._output_.write(b);@b@@b@ this._output_.write(b);@b@ }@b@ this._output_.write(_COMMAND_SE);@b@@b@ this._output_.flush();@b@ }@b@ }@b@@b@ final synchronized void _sendCommand(byte cmd)@b@ throws IOException@b@ {@b@ this._output_.write(255);@b@ this._output_.write(cmd);@b@ this._output_.flush();@b@ }@b@@b@ final synchronized void _processAYTResponse()@b@ {@b@ if (!(this.aytFlag))@b@ {@b@ synchronized (this.aytMonitor)@b@ {@b@ this.aytFlag = true;@b@ this.aytMonitor.notifyAll();@b@ }@b@ }@b@ }@b@@b@ protected void _connectAction_()@b@ throws IOException@b@ {@b@ for (int ii = 0; ii < 256; ++ii)@b@ {@b@ this._doResponse[ii] = 0;@b@ this._willResponse[ii] = 0;@b@ this._options[ii] = 0;@b@ if (this.optionHandlers[ii] != null)@b@ {@b@ this.optionHandlers[ii].setDo(false);@b@ this.optionHandlers[ii].setWill(false);@b@ }@b@@b@ }@b@@b@ super._connectAction_();@b@ this._input_ = new BufferedInputStream(this._input_);@b@ this._output_ = new BufferedOutputStream(this._output_);@b@@b@ for (ii = 0; ii < 256; ++ii)@b@ {@b@ if (this.optionHandlers[ii] != null)@b@ {@b@ if (this.optionHandlers[ii].getInitLocal())@b@ {@b@ _requestWill(this.optionHandlers[ii].getOptionCode());@b@ }@b@@b@ if (this.optionHandlers[ii].getInitRemote())@b@ {@b@ _requestDo(this.optionHandlers[ii].getOptionCode());@b@ }@b@ }@b@ }@b@ }@b@@b@ final synchronized void _sendDo(int option)@b@ throws IOException@b@ {@b@ this._output_.write(_COMMAND_DO);@b@ this._output_.write(option);@b@@b@ this._output_.flush();@b@ }@b@@b@ final synchronized void _requestDo(int option)@b@ throws IOException@b@ {@b@ if (((this._doResponse[option] == 0) && (_stateIsDo(option))) || (_requestedDo(option)))@b@ {@b@ return;@b@ }@b@ _setWantDo(option);@b@ this._doResponse[option] += 1;@b@ _sendDo(option);@b@ }@b@@b@ final synchronized void _sendDont(int option)@b@ throws IOException@b@ {@b@ this._output_.write(_COMMAND_DONT);@b@ this._output_.write(option);@b@@b@ this._output_.flush();@b@ }@b@@b@ final synchronized void _requestDont(int option)@b@ throws IOException@b@ {@b@ if (((this._doResponse[option] == 0) && (_stateIsDont(option))) || (_requestedDont(option)))@b@ {@b@ return;@b@ }@b@ _setWantDont(option);@b@ this._doResponse[option] += 1;@b@ _sendDont(option);@b@ }@b@@b@ final synchronized void _sendWill(int option)@b@ throws IOException@b@ {@b@ this._output_.write(_COMMAND_WILL);@b@ this._output_.write(option);@b@@b@ this._output_.flush();@b@ }@b@@b@ final synchronized void _requestWill(int option)@b@ throws IOException@b@ {@b@ if (((this._willResponse[option] == 0) && (_stateIsWill(option))) || (_requestedWill(option)))@b@ {@b@ return;@b@ }@b@ _setWantWill(option);@b@ this._doResponse[option] += 1;@b@ _sendWill(option);@b@ }@b@@b@ final synchronized void _sendWont(int option)@b@ throws IOException@b@ {@b@ this._output_.write(_COMMAND_WONT);@b@ this._output_.write(option);@b@@b@ this._output_.flush();@b@ }@b@@b@ final synchronized void _requestWont(int option)@b@ throws IOException@b@ {@b@ if (((this._willResponse[option] == 0) && (_stateIsWont(option))) || (_requestedWont(option)))@b@ {@b@ return;@b@ }@b@ _setWantWont(option);@b@ this._doResponse[option] += 1;@b@ _sendWont(option);@b@ }@b@@b@ final synchronized void _sendByte(int b)@b@ throws IOException@b@ {@b@ this._output_.write(b);@b@@b@ _spyWrite(b);@b@ }@b@@b@ final boolean _sendAYT(long timeout)@b@ throws IOException, IllegalArgumentException, InterruptedException@b@ {@b@ boolean retValue = false;@b@ synchronized (this.aytMonitor)@b@ {@b@ synchronized (this)@b@ {@b@ this.aytFlag = false;@b@ this._output_.write(_COMMAND_AYT);@b@ this._output_.flush();@b@ }@b@ this.aytMonitor.wait(timeout);@b@ if (!(this.aytFlag))@b@ {@b@ retValue = false;@b@ this.aytFlag = true;@b@ }@b@ else@b@ {@b@ retValue = true;@b@ }@b@ }@b@@b@ return retValue;@b@ }@b@@b@ void addOptionHandler(TelnetOptionHandler opthand)@b@ throws InvalidTelnetOptionException, IOException@b@ {@b@ int optcode = opthand.getOptionCode();@b@ if (TelnetOption.isValidOption(optcode))@b@ {@b@ if (this.optionHandlers[optcode] == null)@b@ {@b@ this.optionHandlers[optcode] = opthand;@b@ if (!(isConnected())) return;@b@@b@ if (opthand.getInitLocal())@b@ {@b@ _requestWill(optcode);@b@ }@b@@b@ if (!(opthand.getInitRemote())) return;@b@@b@ _requestDo(optcode); return;@b@ }@b@@b@ throw new InvalidTelnetOptionException("Already registered option", optcode);@b@ }@b@@b@ throw new InvalidTelnetOptionException("Invalid Option Code", optcode);@b@ }@b@@b@ void deleteOptionHandler(int optcode)@b@ throws InvalidTelnetOptionException, IOException@b@ {@b@ if (TelnetOption.isValidOption(optcode))@b@ {@b@ if (this.optionHandlers[optcode] == null)@b@ {@b@ throw new InvalidTelnetOptionException("Unregistered option", optcode);@b@ }@b@@b@ TelnetOptionHandler opthand = this.optionHandlers[optcode];@b@ this.optionHandlers[optcode] = null;@b@@b@ if (opthand.getWill())@b@ {@b@ _requestWont(optcode);@b@ }@b@@b@ if (opthand.getDo())@b@ {@b@ _requestDont(optcode);@b@ }@b@@b@ }@b@ else@b@ {@b@ throw new InvalidTelnetOptionException("Invalid Option Code", optcode);@b@ }@b@ }@b@@b@ void _registerSpyStream(OutputStream spystream)@b@ {@b@ this.spyStream = spystream;@b@ }@b@@b@ void _stopSpyStream()@b@ {@b@ this.spyStream = null;@b@ }@b@@b@ void _spyRead(int ch)@b@ {@b@ OutputStream spy = this.spyStream;@b@ if (spy != null)@b@ {@b@ try@b@ {@b@ if (ch != 13)@b@ {@b@ spy.write(ch);@b@ if (ch == 10)@b@ {@b@ spy.write(13);@b@ }@b@ spy.flush();@b@ }@b@ }@b@ catch (IOException e)@b@ {@b@ this.spyStream = null;@b@ }@b@ }@b@ }@b@@b@ void _spyWrite(int ch)@b@ {@b@ if ((!(_stateIsDo(1))) || (!(_requestedDo(1))))@b@ {@b@ OutputStream spy = this.spyStream;@b@ if (spy != null)@b@ {@b@ try@b@ {@b@ spy.write(ch);@b@ spy.flush();@b@ }@b@ catch (IOException e)@b@ {@b@ this.spyStream = null;@b@ }@b@ }@b@ }@b@ }@b@@b@ public void registerNotifHandler(TelnetNotificationHandler notifhand)@b@ {@b@ this.__notifhand = notifhand;@b@ }@b@@b@ public void unregisterNotifHandler()@b@ {@b@ this.__notifhand = null;@b@ }@b@}
2.SocketClient
package org.apache.commons.net;@b@@b@import java.io.Closeable;@b@import java.io.IOException;@b@import java.io.InputStream;@b@import java.io.OutputStream;@b@import java.net.InetAddress;@b@import java.net.InetSocketAddress;@b@import java.net.Socket;@b@import java.net.SocketException;@b@import javax.net.ServerSocketFactory;@b@import javax.net.SocketFactory;@b@@b@public abstract class SocketClient@b@{@b@ public static final String NETASCII_EOL = "\r\n";@b@ private static final SocketFactory __DEFAULT_SOCKET_FACTORY = SocketFactory.getDefault();@b@ private static final ServerSocketFactory __DEFAULT_SERVER_SOCKET_FACTORY = ServerSocketFactory.getDefault();@b@ private ProtocolCommandSupport __commandSupport;@b@ protected int _timeout_;@b@ protected Socket _socket_;@b@ protected int _defaultPort_;@b@ protected InputStream _input_;@b@ protected OutputStream _output_;@b@ protected SocketFactory _socketFactory_;@b@ protected ServerSocketFactory _serverSocketFactory_;@b@ private static final int DEFAULT_CONNECT_TIMEOUT = 0;@b@ protected int connectTimeout = 0;@b@ private int receiveBufferSize = -1;@b@ private int sendBufferSize = -1;@b@@b@ public SocketClient()@b@ {@b@ this._socket_ = null;@b@ this._input_ = null;@b@ this._output_ = null;@b@ this._timeout_ = 0;@b@ this._defaultPort_ = 0;@b@ this._socketFactory_ = __DEFAULT_SOCKET_FACTORY;@b@ this._serverSocketFactory_ = __DEFAULT_SERVER_SOCKET_FACTORY;@b@ }@b@@b@ protected void _connectAction_()@b@ throws IOException@b@ {@b@ this._socket_.setSoTimeout(this._timeout_);@b@ this._input_ = this._socket_.getInputStream();@b@ this._output_ = this._socket_.getOutputStream();@b@ }@b@@b@ public void connect(InetAddress host, int port)@b@ throws SocketException, IOException@b@ {@b@ this._socket_ = this._socketFactory_.createSocket();@b@ if (this.receiveBufferSize != -1) this._socket_.setReceiveBufferSize(this.receiveBufferSize);@b@ if (this.sendBufferSize != -1) this._socket_.setSendBufferSize(this.sendBufferSize);@b@ this._socket_.connect(new InetSocketAddress(host, port), this.connectTimeout);@b@ _connectAction_();@b@ }@b@@b@ public void connect(String hostname, int port)@b@ throws SocketException, IOException@b@ {@b@ connect(InetAddress.getByName(hostname), port);@b@ }@b@@b@ public void connect(InetAddress host, int port, InetAddress localAddr, int localPort)@b@ throws SocketException, IOException@b@ {@b@ this._socket_ = this._socketFactory_.createSocket();@b@ if (this.receiveBufferSize != -1) this._socket_.setReceiveBufferSize(this.receiveBufferSize);@b@ if (this.sendBufferSize != -1) this._socket_.setSendBufferSize(this.sendBufferSize);@b@ this._socket_.bind(new InetSocketAddress(localAddr, localPort));@b@ this._socket_.connect(new InetSocketAddress(host, port), this.connectTimeout);@b@ _connectAction_();@b@ }@b@@b@ public void connect(String hostname, int port, InetAddress localAddr, int localPort)@b@ throws SocketException, IOException@b@ {@b@ connect(InetAddress.getByName(hostname), port, localAddr, localPort);@b@ }@b@@b@ public void connect(InetAddress host)@b@ throws SocketException, IOException@b@ {@b@ connect(host, this._defaultPort_);@b@ }@b@@b@ public void connect(String hostname)@b@ throws SocketException, IOException@b@ {@b@ connect(hostname, this._defaultPort_);@b@ }@b@@b@ public void disconnect()@b@ throws IOException@b@ {@b@ closeQuietly(this._socket_);@b@ closeQuietly(this._input_);@b@ closeQuietly(this._output_);@b@ this._socket_ = null;@b@ this._input_ = null;@b@ this._output_ = null;@b@ }@b@@b@ private void closeQuietly(Socket socket) {@b@ if (socket != null)@b@ try {@b@ socket.close();@b@ }@b@ catch (IOException e) {@b@ }@b@ }@b@@b@ private void closeQuietly(Closeable close) {@b@ if (close != null)@b@ try {@b@ close.close();@b@ }@b@ catch (IOException e)@b@ {@b@ }@b@ }@b@@b@ public boolean isConnected()@b@ {@b@ if (this._socket_ == null)@b@ return false;@b@@b@ return this._socket_.isConnected();@b@ }@b@@b@ public boolean isAvailable()@b@ {@b@ if (isConnected())@b@ {@b@ try {@b@ if (this._socket_.getInetAddress() == null) return false;@b@ if (this._socket_.getPort() == 0) return false;@b@ if (this._socket_.getRemoteSocketAddress() == null) return false;@b@ if (this._socket_.isClosed()) { return false;@b@ }@b@@b@ if (this._socket_.isInputShutdown()) return false;@b@ if (this._socket_.isOutputShutdown()) return false;@b@@b@ this._socket_.getInputStream();@b@ this._socket_.getOutputStream();@b@ }@b@ catch (IOException ioex)@b@ {@b@ return false;@b@ }@b@ return true;@b@ }@b@ return false;@b@ }@b@@b@ public void setDefaultPort(int port)@b@ {@b@ this._defaultPort_ = port;@b@ }@b@@b@ public int getDefaultPort()@b@ {@b@ return this._defaultPort_;@b@ }@b@@b@ public void setDefaultTimeout(int timeout)@b@ {@b@ this._timeout_ = timeout;@b@ }@b@@b@ public int getDefaultTimeout()@b@ {@b@ return this._timeout_;@b@ }@b@@b@ public void setSoTimeout(int timeout)@b@ throws SocketException@b@ {@b@ this._socket_.setSoTimeout(timeout);@b@ }@b@@b@ public void setSendBufferSize(int size)@b@ throws SocketException@b@ {@b@ this.sendBufferSize = size;@b@ }@b@@b@ protected int getSendBufferSize()@b@ {@b@ return this.sendBufferSize;@b@ }@b@@b@ public void setReceiveBufferSize(int size)@b@ throws SocketException@b@ {@b@ this.receiveBufferSize = size;@b@ }@b@@b@ protected int getReceiveBufferSize()@b@ {@b@ return this.receiveBufferSize;@b@ }@b@@b@ public int getSoTimeout()@b@ throws SocketException@b@ {@b@ return this._socket_.getSoTimeout();@b@ }@b@@b@ public void setTcpNoDelay(boolean on)@b@ throws SocketException@b@ {@b@ this._socket_.setTcpNoDelay(on);@b@ }@b@@b@ public boolean getTcpNoDelay()@b@ throws SocketException@b@ {@b@ return this._socket_.getTcpNoDelay();@b@ }@b@@b@ public void setKeepAlive(boolean keepAlive)@b@ throws SocketException@b@ {@b@ this._socket_.setKeepAlive(keepAlive);@b@ }@b@@b@ public boolean getKeepAlive()@b@ throws SocketException@b@ {@b@ return this._socket_.getKeepAlive();@b@ }@b@@b@ public void setSoLinger(boolean on, int val)@b@ throws SocketException@b@ {@b@ this._socket_.setSoLinger(on, val);@b@ }@b@@b@ public int getSoLinger()@b@ throws SocketException@b@ {@b@ return this._socket_.getSoLinger();@b@ }@b@@b@ public int getLocalPort()@b@ {@b@ return this._socket_.getLocalPort();@b@ }@b@@b@ public InetAddress getLocalAddress()@b@ {@b@ return this._socket_.getLocalAddress();@b@ }@b@@b@ public int getRemotePort()@b@ {@b@ return this._socket_.getPort();@b@ }@b@@b@ public InetAddress getRemoteAddress()@b@ {@b@ return this._socket_.getInetAddress();@b@ }@b@@b@ public boolean verifyRemote(Socket socket)@b@ {@b@ InetAddress host1 = socket.getInetAddress();@b@ InetAddress host2 = getRemoteAddress();@b@@b@ return host1.equals(host2);@b@ }@b@@b@ public void setSocketFactory(SocketFactory factory)@b@ {@b@ if (factory == null)@b@ this._socketFactory_ = __DEFAULT_SOCKET_FACTORY;@b@ else@b@ this._socketFactory_ = factory;@b@ }@b@@b@ public void setServerSocketFactory(ServerSocketFactory factory)@b@ {@b@ if (factory == null)@b@ this._serverSocketFactory_ = __DEFAULT_SERVER_SOCKET_FACTORY;@b@ else@b@ this._serverSocketFactory_ = factory;@b@ }@b@@b@ public void setConnectTimeout(int connectTimeout)@b@ {@b@ this.connectTimeout = connectTimeout;@b@ }@b@@b@ public int getConnectTimeout()@b@ {@b@ return this.connectTimeout;@b@ }@b@@b@ public ServerSocketFactory getServerSocketFactory()@b@ {@b@ return this._serverSocketFactory_;@b@ }@b@@b@ public void addProtocolCommandListener(ProtocolCommandListener listener)@b@ {@b@ getCommandSupport().addProtocolCommandListener(listener);@b@ }@b@@b@ public void removeProtocolCommandListener(ProtocolCommandListener listener)@b@ {@b@ getCommandSupport().removeProtocolCommandListener(listener);@b@ }@b@@b@ protected void fireReplyReceived(int replyCode, String reply)@b@ {@b@ if (getCommandSupport().getListenerCount() > 0)@b@ getCommandSupport().fireReplyReceived(replyCode, reply);@b@ }@b@@b@ protected void fireCommandSent(String command, String message)@b@ {@b@ if (getCommandSupport().getListenerCount() > 0)@b@ getCommandSupport().fireCommandSent(command, message);@b@ }@b@@b@ protected void createCommandSupport()@b@ {@b@ this.__commandSupport = new ProtocolCommandSupport(this);@b@ }@b@@b@ protected ProtocolCommandSupport getCommandSupport()@b@ {@b@ return this.__commandSupport;@b@ }@b@}