Code example for Socket

Methods: getInetAddress, getInputStream, getLocalPort, getOutputStream, getPort, setSoTimeout

0
       Create a TCPConnection from an existing socket. 
       @param socket The socket to attach to. 
       @throws IOException If there is a problem opening the streams. 
    */ 
    public TCPConnection(Socket socket) throws IOException {
        super(socket.getInputStream(), socket.getOutputStream());
        this.socket = socket;
        socket.setSoTimeout(1000);
        setName("TCPConnection: local port " + socket.getLocalPort() + ", endpoint = " + socket.getInetAddress() + ":" + socket.getPort());
    } 
 
    @Override 
    protected void shutdownImpl() { 
        super.shutdownImpl(); 
        try { 
            socket.close();
        } 
        catch (IOException e) {
            Logger.error("Error closing TCP connection", e);
        } 
    }