sockets - Java - readObject() and setSoTimeout() -



sockets - Java - readObject() and setSoTimeout() -

so, wrote thread on client side , tries readobject() socket stream.

this thread runs long client connected.

the connection server can closed on client's gui. if client decides disconnect(this not exit client program) clicking "disconnect" menu option, socket closed , isconnected set false.

since clients read thread tries readobject() stream, while connection can closed via gui, set timeout 250ms (setsotimeout(250)).

@override public void run() { this.connection = this.connectionhandler.getsocket(); while(connectionhandler.isconnected()) { this.readcircle(); } this.connectionhandler.setreadtaskrunning(false); } private void readcircle() { seek { this.connection.setsotimeout(250); this.connectionhandler.readdata(); //this uses readobject(). } catch(sockettimeoutexception timeout){} catch(...){}

}

i know readobject() block, , check if client still connected, wraped in while, checks (every timeout) if client socket still connected.

my question now:

in case, if readobject() starts object passed server, tries read it, while processing timeout occurs, info on stream "damaged" in way, because canceled. or should allow readobject() block , grab exception if gui thread wants close socket.

i'm not experienced sockets , maybe approach wrong @ all.

socket read timeout cause socketexception thrown readobject(). not able reuse objectinputstream, , stream "damaged" because current position remain largely undefined.

this can fixed closing , reopening connection.

java sockets socket-timeout-exception

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -