Click to See Complete Forum and Search --> : Algorithm Assistance....


JMS
October 3rd, 2005, 03:04 PM
I'm looking to write a class which will be able to autodiscover other instances of itself on the network within the subnet and then open up conversations with those instances of itself...


My general algorithm is this...

(1)Class comes up and broadcasts I'm alive message containing it's ip address and a udp and tcp port which it will be listening on.

(2) Initializes two server threads one UDP and one TCP to listen for any conversations.

(3) UDP thread when it hears an I'm alive message inserts the new ip address and ports into a server vector and opens up a TCP socket to the new guy sending it his contact information... ip, udp port, tcp port.

(4) When the class is destroyed the destructor circulates through the siblings vector and informs everybody he is going down and to remove him from their vectors.

I'm looking for any thoughts on this algorithm...

One problem I'm haveing now is that if there are two instances of the class on the same machine the second instance can not bind to the UDP port to recieve the broadcast messages. If I set the socket option SO_REUSEADDR then the second instance can bind to the socket but it still does not recieve the broadcast messages.

Any thoughts or suggestions or is my algorithm just not well thought out..

Ejaz
October 8th, 2005, 03:37 PM
This is pretty much similiar to the network game programming, where a player hosts a game at a network. The other instances discover the no. of available games on the network with the initial informaiton. The later player can choose any game of his preference and connect with it.

You can get implementation of this in different network libraries, which are specifically designed for network game engines (OpenTNL/RakNet/DirectPlay etc).