CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2000
    Location
    Washington DC, USA
    Posts
    715

    Algorithm Assistance....??

    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..
    Last edited by JMS; October 3rd, 2005 at 04:25 PM.

  2. #2
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211

    Re: Algorithm Assistance....

    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).
    Last edited by Ejaz; October 8th, 2005 at 03:39 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured