Code example for Socket

Methods: close, getInputStream, getOutputStream, setSoTimeout

0
        ObjectOutputStream oos;
        ObjectInputStream ois;
        Object tempObject;
 
        try { 
            socket = new Socket(inetAddresses[0],3333);
            socket.setSoTimeout(1200);
            oos = new ObjectOutputStream(socket.getOutputStream());
            ois = new ObjectInputStream(socket.getInputStream());
            oos.writeObject("<command>getstat</command>");
            tempObject = ois.readObject();
            if (SingleStat.class.isInstance(tempObject)){
                publishProgress((SingleStat)tempObject);
            } 
 
        } catch (SocketTimeoutException e){
            publishProgress(new SingleStat(-1, "Server unreacheble: "+e.getMessage() ));
            return null; 
 
        } catch (IOException e) {
            publishProgress(new SingleStat(-1, "Server unreacheble: "+e.getMessage() ));
            socket = null;
            oos = null;
            return null; 
 
        } catch (ClassNotFoundException e){
            publishProgress(new SingleStat(-1, "Server is crazy: "+e.getMessage() ));
            return null; 
        } 
        finally { 
            try { 
                socket.close();
            } catch (Exception e) {}
            return null; 
        } 
 
    }