Archived

This topic is now archived and is closed to further replies.

wingcom

DirectPlay FindHosts [c#]

Recommended Posts

wingcom    122
This is regarding Peer to Peer connections, there is no host but another instance of the app is trying to connect, enumerating all the possible host in a subnet. so how can I tell that the FindHosts has finish enumeration and display the message "FAIL TO FIND VALID HOST". I know I should use CancelAsyncOperation to cancel the FindHosts request, but I dont know when I should use it, any advice? Thanks I have 2 buttons in the form, button 1 will set the parameter host to true and button 2 will set it to false
private Peer connection = null;

private void InitializeDirectPlay(bool host)
{
    connection = new Peer();

    connection.FindHostResponse += new FindHostResponseEventHandler(OnFindHost);
.
.
    if(host)
    {
        connection.Host(desc, deviceAddress);
    }
    else
    {
        connection.FindHosts(desc, null, deviceAddress, null, 0, 0, 0, FindHostsFlags.OkToQueryForAddressing);
     }
}

private void OnFindHost(object sender,FindHostResponseEventArgs e)
{
    lock(this)
    {
        if(connected)
            return;
				
        connected = true;
        string foundsession = String.Format("Found Session {0}), trying to connect.", e.Message.ApplicationDescription.SessionName);

        this.BeginInvoke(new AddTextCallBack(AddText), new object[]{foundsession});

	((Peer)sender).Connect( e.Message.ApplicationDescription, e.Message.AddressSender, e.Message.AddressDevice,null,ConnectFlags.OkToQueryForAddressing);
     }
}
[edited by - wingcom on March 30, 2004 10:52:23 PM]

Share this post


Link to post
Share on other sites