How can the TCP socket creation class gets notified that one new peer is added to the registry?

I am implementing a P2P service. The idea is using UDP to search for peers and build it's own registry. And using TCP to do the real communication. I want to create one more new TCP socket connection, if there's one more peer added to this peer's registry. The registry is implemented in hashmap . How can the TCP socket creation class gets notified that one new peer is added to the registry?

Answers


Simply implement a class like 'TcpConnectionManager' which registers itself with the registry - lets call it 'P2PConnectionRegistry' at startup. (The registry has to be a class maintaining a HashMap - it cannot be a HashMap.).

If a new connection has to be created, you call p2pConnRegistry.addConnection(...); from somewhere (e.g. UI).

This method adds the required params it's internal data structure (e.g. the HashMap) - and then calls registryListener.connectionAdded(...); This registryListener is a instance of TcpConnectionManager.

This is a very simple model for "seperation of concerns".

I hope this was your question it it helps, greetings, Michael


Need Your Help

Unknow length of Http Response

jsp java-ee servlets

We know that in Java EE servlet/jsp, client can obtain one http response for one http request. I want to implement something that has unknown length of http response. I want the server keep on push...

How do I create an ASMX web service page without a code behind file

c# asp.net

I have been able to create ASPX pages without the code behind, but I can't for the life of me figure out the magic combination to get an ASMX page to work without a code behind. Is this even possib...