JAVA : When to use Socket setSoTimeout? -


i making application client sends message server , waits 5 seconds (lets assume) server respond , if there no return message, retries again. if server responds message client process it. goes on in loop , again happens after sometime.

for purpose thinking use setsotimeout(time) on client socket after reading javadoc , lot of explanations on internet confused whether approach right.

what read on internet

(1) if use setsotimeout on socket gives timeout duration in connection needs established , if not established retries establish connection given time.

(2) if use setsotimeout on socket waits incoming messages specified time interval , if no message received stops waiting.

my questions -

(1) of above true ?

(2) if second statement true, can use implementation ?

(3) if second statement true, when timeout timer kickoff ? when declare socket , set timeout period on or when send message ?

if either of explanation don't apply case should wait fixed interval of time on client side server reply ? if reply come should process , move on , redo same process. if reply doesn't come should move ahead , redo whole process again.

(1) if use setsotimeout on socket gives timeout duration in connection needs established , if not established retries establish connection given time.

this drivel.

(2) if use setsotimeout on socket waits incoming messages specified time interval , if no message received stops waiting.

this more accurate, there no such thing message in tcp.

the correct explanation blocks specified timeout @ least 1 byte arrive. if nothing arrives within timeout, sockettimeoutexception thrown.

i don't know why reading random internet garbage when official documentation available.

(1) of above true?

neither.

(2) if second statement true, can use implementation?

it isn't, second part doesn't apply, if statement true can use part of implementation. don't have ask.

(3) if second statement true, when timeout timer kickoff exactly?

when call read().

is when declare socket , set timeout period on or when send message?

neither.

if either of explanation don't apply case should wait fixed interval of time on client side server reply?

set read timeout.

if reply come should process , move on , redo same process. if reply doesn't come should move ahead , redo whole process again.

is question?


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -