import java.net.*; import java.io.*; public class SocketControl extends Socket { public final int OkResult=220; public final int ErrorResult=500; private InputStream mInputStream=null; private OutputStream mOutputStream=null; private boolean mIsConnected=false; public SocketControl() { } public SocketControl(String strHost,int port)throws IOException { super(strHost,port); // try{mInputStream=getInputStream();} // catch(IOException exception){close();return;} // try{mOutputStream=getOutputStream();} // catch(IOException exception){close();return;} isConnected(true); } public SocketControl(InetAddress inetAddress,int port)throws IOException { super(inetAddress,port); try{mInputStream=getInputStream();} catch(IOException exception){close();return;} try{mOutputStream=getOutputStream();} catch(IOException exception){close();return;} isConnected(true); } public void closeSocket()throws IOException { isConnected(false); close(); } public boolean isConnected() { return mIsConnected; } private void isConnected(boolean isConnected) { mIsConnected=isConnected; } public String readLine() { byte streamByte[]; String strLine=new String(); if(!isConnected())return strLine; strLine=new String(); while(true) { streamByte=new byte[1]; try{mInputStream.read(streamByte);} catch(IOException exception){break;} if(13==streamByte[0])continue; else if(10==streamByte[0])break; strLine+=new String(streamByte); } return strLine; } public boolean writeLine(String strLine) { if(!isConnected()||0==strLine.length())return false; strLine+=new String("\r\n"); byte streamData[]=strLine.getBytes(); try{mOutputStream.write(streamData);} catch(IOException exception){return false;} return true; } public int getResultCode(String strLine) { if(0==strLine.length())return 0; String strResult=new String(); int strIndex=0; while(true) { if(strIndex>=3)break; if(' '==strLine.charAt(strIndex))break; strResult+=strLine.charAt(strIndex); strIndex++; } if(0==strResult.length())return 0; return Integer.parseInt(strResult); } public String getResult(String strLine) { String strResult=new String(); int strIndex=0; int strLength=strLine.length(); if(0==strLength)return strResult; while(' '!=strLine.charAt(strIndex)&&strIndex=strLength)return strResult; while(strIndex