I'm making a zero config p2p app for file transfers and chat using Java and UDP. Well, since I'm starting from scratch I need to implement my own discovery protocol which isn't hard , but it needs to flow on the network at the same time the data is getting transfered. Obvioulsy this is going to require quite a few threads, some of which will just block, but I see no way around it.
Option 1 - Seperate Discovery and App Data into differnet ports
You would have one thread listen on port f and another broadcast announcement packets also on port f. These would be seperate from the most of the program and would just be resposible for keeping the information of clients and expiring/updating them as required.
Then, there would be a second class that would listen on port p monitoring the incoming data and handling it as required whether that be buildign a file or what. Like above, there would also be a thread to transfer data from the client sending it over port p.
Option 2 -Integrate Discovery and App Data and use call backs to handle it
There would be only two threads that deal with the network. One to listen and call back the handler tha matches the header on the packet and oen to send out all the packets from the client. Threads could be used later to offload work from this and just store the data in a queue.
I hope that wasn't too ambiguous
. I'm open to questions/suggestions/other ideas.
Option 1 - Seperate Discovery and App Data into differnet ports
You would have one thread listen on port f and another broadcast announcement packets also on port f. These would be seperate from the most of the program and would just be resposible for keeping the information of clients and expiring/updating them as required.
Then, there would be a second class that would listen on port p monitoring the incoming data and handling it as required whether that be buildign a file or what. Like above, there would also be a thread to transfer data from the client sending it over port p.
Option 2 -Integrate Discovery and App Data and use call backs to handle it
There would be only two threads that deal with the network. One to listen and call back the handler tha matches the header on the packet and oen to send out all the packets from the client. Threads could be used later to offload work from this and just store the data in a queue.
I hope that wasn't too ambiguous
