public static void writeObject ( final InetAddress inetAddress , final int port , final Object objectToSend ) throws IOException { Socket socketToClient = null ; ObjectOutputStream oos = null ; try { socketToClient = new Socket ( inetAddress , port ) ; oos = new ObjectOutputStream ( new BufferedOutputStream ( socketToClient . getOutputStream ( ) ) ) ; oos . writeObject ( objectToSend ) ; oos . close ( ) ; socketToClient . close ( ) ; } catch ( final IOException e ) { LOGGER . error ( "IOException occured by trying to write the object." , e ) ; throw e ; } finally { try { if ( oos != null ) { oos . close ( ) ; } close ( socketToClient ) ; } catch ( final IOException e ) { LOGGER . error ( "IOException occured by trying to close the socket." , e ) ; throw e ; } } }
Writes the given Object to the given InetAddress who listen to the given port .