Example usage for java.net Socket getSoLinger

List of usage examples for java.net Socket getSoLinger

Introduction

In this page you can find the example usage for java.net Socket getSoLinger.

Prototype

public int getSoLinger() throws SocketException 

Source Link

Document

Returns setting for SocketOptions#SO_LINGER SO_LINGER .

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket client = new Socket("google.com", 80);
    client.setSoLinger(true, 1000);//from  w w w  .  ja  v  a 2 s.c o m
    System.out.println(client.getSoLinger());

    client.close();
}

From source file:org.mule.transport.tcp.TcpConnector.java

public void configureSocket(boolean client, Socket socket) throws SocketException {
    // There is some overhead in setting socket timeout and buffer size, so we're
    // careful here only to set if needed

    if (newValue(getReceiveBufferSize(), socket.getReceiveBufferSize())) {
        socket.setReceiveBufferSize(getReceiveBufferSize());
    }/*  ww w  .j  a v a  2s . c om*/
    if (newValue(getSendBufferSize(), socket.getSendBufferSize())) {
        socket.setSendBufferSize(getSendBufferSize());
    }
    if (client) {
        if (newValue(getClientSoTimeout(), socket.getSoTimeout())) {
            socket.setSoTimeout(getClientSoTimeout());
        }
    } else {
        if (newValue(getServerSoTimeout(), socket.getSoTimeout())) {
            socket.setSoTimeout(getServerSoTimeout());
        }
    }
    if (newValue(getSocketSoLinger(), socket.getSoLinger())) {
        socket.setSoLinger(true, getSocketSoLinger());
    }
    try {
        socket.setTcpNoDelay(isSendTcpNoDelay());
    } catch (SocketException e) {
        // MULE-2800 - Bug in Solaris
    }
    socket.setKeepAlive(isKeepAlive());
}

From source file:org.springframework.integration.ip.tcp.connection.AbstractTcpConnection.java

public AbstractTcpConnection(Socket socket, boolean server, boolean lookupHost) {
    this.server = server;
    InetAddress inetAddress = socket.getInetAddress();
    if (inetAddress != null) {
        this.hostAddress = inetAddress.getHostAddress();
        if (lookupHost) {
            this.hostName = inetAddress.getHostName();
        } else {//from   w  ww .j  a va 2 s.co m
            this.hostName = this.hostAddress;
        }
    }
    int port = socket.getPort();
    this.connectionId = this.hostName + ":" + port + ":" + UUID.randomUUID().toString();
    try {
        this.soLinger = socket.getSoLinger();
    } catch (SocketException e) {
    }
}

From source file:org.springframework.integration.ip.tcp.connection.TcpConnectionSupport.java

/**
 * Creates a {@link TcpConnectionSupport} object and publishes a
 * {@link TcpConnectionOpenEvent}, if an event publisher is provided.
 * @param socket the underlying socket.// ww  w  . ja va 2  s  .  co m
 * @param server true if this connection is a server connection
 * @param lookupHost true if reverse lookup of the host name should be performed,
 * otherwise, the ip address will be used for identification purposes.
 * @param applicationEventPublisher the publisher to which open, close and exception events will
 * be sent; may be null if event publishing is not required.
 * @param connectionFactoryName the name of the connection factory creating this connection; used
 * during event publishing, may be null, in which case "unknown" will be used.
 */
public TcpConnectionSupport(Socket socket, boolean server, boolean lookupHost,
        ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) {
    this.server = server;
    InetAddress inetAddress = socket.getInetAddress();
    if (inetAddress != null) {
        this.hostAddress = inetAddress.getHostAddress();
        if (lookupHost) {
            this.hostName = inetAddress.getHostName();
        } else {
            this.hostName = this.hostAddress;
        }
    }
    int port = socket.getPort();
    this.connectionId = this.hostName + ":" + port + ":" + UUID.randomUUID().toString();
    try {
        this.soLinger = socket.getSoLinger();
    } catch (SocketException e) {
    }
    this.applicationEventPublisher = applicationEventPublisher;
    if (connectionFactoryName != null) {
        this.connectionFactoryName = connectionFactoryName;
    }
    this.publishConnectionOpenEvent();
    if (logger.isDebugEnabled()) {
        logger.debug("New connection " + this.getConnectionId());
    }
}