java - TCP Client Accepting Objects -


i writing java program needs continuously accept serialized objects throughout run of application. objects sent server requested user.

my main application initializes tcp client (extends thread) in run method, trying read objects line function.

pseudocode follows:

*tcp client extends thread  *global vars: ip, port, socket, oi stream, oo stream, object reference  *run()       make connection  *getobject()       object reference = (object).readobject()       return object 

my main application calls client.getobject() in update loop. there may or not object waiting.

am going wrong way?

are trying "classic" server behavior or non-blocking io?

if it's former, i'd recommend blocking queue on server accept incoming requests , pool of threads process them. have server assign thread process request when comes in until thread pool exhausted; queue requests until threads freed , returned pool.

non-blocking io matter entirely. @ how netty , node.js designed , implemented that.

i never have class extend thread - it's unlikely you'll add significant new behavior. implement runnable instead , give thread instance run.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -