java - How to use so-linger to keep server connection for some time -


i have tcp gateway built using spring integration. server able process request client , send response. client giving socketexception

java.net.socketexception: connection reset     @ java.net.socketinputstream.read(socketinputstream.java:168)     @ sun.nio.cs.streamdecoder.readbytes(streamdecoder.java:264)     @ sun.nio.cs.streamdecoder.implread(streamdecoder.java:306)     @ sun.nio.cs.streamdecoder.read(streamdecoder.java:158)     @ sun.nio.cs.streamdecoder.read0(streamdecoder.java:107)     @ sun.nio.cs.streamdecoder.read(streamdecoder.java:93)     @ java.io.inputstreamreader.read(inputstreamreader.java:151) 

it seems server closing connection before client reads data. hence use so-linger.

setsolinger supposed keep server socket open linger time. javadoc setsolinger says enable/disable so_linger specified linger time in seconds.

see https://docs.oracle.com/javase/6/docs/api/java/net/socket.html#setsolinger%28boolean,%20int%29

see spring integration document setting solinger.

my spring context.xml :

    <int-ip:tcp-connection-factory id="crlfserver"             type="server"             port="${availableserversocket}"             single-use="true"             so-timeout="10000"             using-nio="false"              serializer="connectionserializedeserialize"             deserializer="connectionserializedeserialize"             so-linger="2000"/>          <bean id="connectionserializedeserialize" class="org.springframework.integration.ip.tcp.serializer.bytearraystxetxserializer"/>          <int-ip:tcp-inbound-gateway id="gatewaycrlf"             connection-factory="crlfserver"             request-channel="serverbytes2stringchannel"             error-channel="errorchannel"             reply-timeout="10000"/> <!-- reply-timeout works on inbound-gateway -->          <int:channel id="tosa" />          <int:service-activator input-channel="tosa"             ref="myservice"             method="prepare"/>          <int:object-to-string-transformer id="serverbytes2string"             input-channel="serverbytes2stringchannel"             output-channel="tosa"/>          <int:transformer id="errorhandler"             input-channel="errorchannel"             expression="payload.failedmessage.payload + ':' + payload.cause.message"/> 

i not sure whether spring integration takes linger time in seconds or milli seconds. there other flag set server socket kept open till client reads data.

i seeing socket connection closed event sending response service bean. server not seem wait. please how set so-linger time or suggest alternative. thank you.

here log:

2016-06-01 15:43:46,276 myservice response:                 accept:e211001:  2016-06-01 15:43:46.293 debug [pool-1-thread-2][org.springframework.context.support.genericxmlapplicationcontext] publishing event in org.springframework.context.support.genericxmlapplicationcontext@7a187814: tcpconnectioncloseevent [source=org.springframework.integration.ip.tcp.connection.tcpnetconnection@4c4b11e9], [factory=crlfserver, connectionid=22.220.220.222:1034:5678:77483643-2156-427f-96dd-a513670a75a3] **closed**  2016-06-01 15:43:46.294 debug [pool-1-thread-2][org.springframework.context.support.genericxmlapplicationcontext] publishing event in org.springframework.context.support.genericxmlapplicationcontext@7a187814: tcpconnectionexceptionevent [source=org.springframework.integration.ip.tcp.connection.tcpnetconnection@4c4b11e9, cause=java.net.socketexception: socket closed], [factory=crlfserver, connectionid=22.220.220.222:1034:5678:77483643-2156-427f-96dd-a513670a75a3] 

spring integration performs no conversion on value, it's seconds.

the behavior describe sounds so-linger 0 (immediate rst sent close()).

you don't need linger purpose; when it's not set tcp stack should gracefully close socket.

you need run network monitor figure out what's happening.

if trust client close socket, remove

single-use="true"

or set false server doesn't close socket after sending reply.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo