With the session up and being hosted by one of the peers, you need another player to join this session. See Listing 16.5 for the code to have the player join the session. Listing 16.5. Joining a Session/// <summary> /// Join an existing session with the following hostname /// </summary> public void Join(string hostName) { // Create the application description ApplicationDescription desc = new ApplicationDescription(); desc.GuidApplication = gameGuid; // Unique ID all games will use // Now try to find the host and connect to it using(Address localAddress = new Address()) { // Set the local provider localAddress.ServiceProvider = Address.ServiceProviderTcpIp; // Set the host's address name deviceAddress.AddComponent(Address.KeyHostname, hostName); // Search for hosts. networkDevice.FindHosts(desc, deviceAddress, localAddress, null, 0, 0, 0, FindHostsFlags.None); } } As you see in this code, you still need to use the application description before you can connect. However, the only thing you know (or need to know) about the application is the Guid because that is what uniquely identifies the application. When you plan to join an existing session, you need two separate addresses: one to represent the address you're using to connect and a second representing the address you are connecting to. So before you attempt to call the FindHosts method, you need to create a new address and set the service provider to TCP/IP, like the one you've already created. Finally, you add the hostname you are trying to connect to and call the FindHosts method. |