java - How to get a socket object without a reference variable? -


i've been thinking day, dont think if title correct 1 here goes, let me explain situation: im working on project, server made in java clients made in delphi. conections good, multiple clients own threads, i/o working good. clients send strings server read bufferedreader. depending on reserved words server receives, makes action. before client sends string, inserts information sql server database server can go , check after getting order/command via socket. server obtains information in database, process it, , send to... let's call "the dark side".

at moment transaction done, , info sent dark side, server inserts information... cough cough, dark information database table client can go , take requested. but, need report client! ("yo, check again database bro, want there :3").

the conection, socket made in other class. not 1 want use answer client, if dont have socket, dont have outputstream, need talk back. class, 1 processing , sending information dark side, going working hundred of transactions in group.

my issue here: can't report client done because dont have sockets references in class. instance clients thread like:

new client(socket).start();  

objects without references variables, but, have option can take: store sockets , ip's in hashmap object @ moment new connection made, this:

sockets.put(newsocket.getinetaddress().gethostaddress(), newsocket); 

then can socket(so can outputstream , answer) calling static method this:

 public static socket getsocket(string ip) {          socket requestedsocket;         requestedsocket = sockets.get(ip);          return requestedsocket;     } 

but want tell me if there better way of doing this, better storing of sockets in list/hashmap. how can objects without reference variables ? or maybe thats way of doing , im trying overpass limits.

p.s.: tried store client objects in database, serializing them, sockets can't serialized.

thanks.

this design issue you. need keep track of them somewhere, 1 solution might create singleton class [socketmapmanager] instance holds hashmap, can access statically other classes. http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -