简体   繁体   中英

How to set SO_REUSEADDR in a TCP Outbound Adapter?

I have several TCP/IP Outbound Adapters to send Messages to connecting clients. The TCP/IP protocol of communication requires the socket flags to be set: TCP_NODELAY, SO_REUSEADDR, and SO_KEEPALIVE.

    @Override
    public void start(String context, int port) {
        TcpServerConnectionFactorySpec server = Tcp.netServer(port)
                .id(context)
                .soTcpNoDelay(true)
                .soKeepAlive(true)
                .serializer(new ByteArrayLengthHeaderSerializer())
                ;
        IntegrationFlow flow = f -> f.handle(Tcp.outboundAdapter(server));
        this.registrations.put(context, flowContext.registration(flow).register());
    }

How do I set the socket's SO_REUSEADDR flag to TRUE?

Implement a custom TcpSocketSupport ...

public class MySocketSupport extends DefaultTcpSocketSupport {

    @Override
    public void postProcessServerSocket(ServerSocket serverSocket) {
        ...
    }

}

then...

.tcpSocketSupport(new MySocketSupport())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM