DirectX:DirectPlay:Tutorials:VB:DX7:Initializing a Connection
From GPWikiOnce the user has (somehow) selected the desired service provider, we must attempt to make a connection using that provider. This might sound like we're attempting to physically "connect" to another computer, but we're not... yet. When we initialize a connection, all that we're checking is that the service provider selected is indeed available on the computer. For example, if the user selects "modem," but does not have a modem on his computer (or it's not configured correctly), then we will get an error (which we can trap). If the user selects "modem" and HAS a modem, then nothing happens and execution continues... no dialing, no answering, nothing YET! Observe: Dim objDPAddress As DirectPlayAddress Set objDPAddress = objEnumConnections.GetAddress(Index + 1) Call dp.InitializeConnection(objDPAddress) The DirectPlayAddress object is an interesting one. What we're doing here is filling it with information on the service provider selected (assume that Index is the index value returned when the user clicked on the listbox containing the service provider enumeration), and using this information to initialize that service provider with a call to the DirectPlay4.InitializeConnection method. BUT, not only can a DirectPlayAddress object hold service provider information, it can also contain specific information regarding the computer we intend to connect to! For example, if we already KNEW the IP address of the computer we're going to connect to (a server, perhaps), we would like to pass this information along to the service provider at this point. The service provider would remember this information. Later on, when we attempt to enumerate sessions or create a new session (see the NEXT tutorial topic), the service provider would normally present the user with a dialog box asking for information (phone number to dial, IP address to send packets to, etc, etc). If we already knew this info, however, we could have inserted it in the DirectPlayAddress object prior to the DirectPlay4.InitializeConnection call using one of the DirectPlayLobby3 "Create Address" methods (ie. DirectPlayLobby3.CreateModemAddress). A short explanation about this can be found here. The code I've given above does not pass any special info along to the service provider, so when the time comes to create a session, the provider will have to ask the user for some input. There's blood in the water... the sharks are circling. Check out the Starting/Joining a Game to get one step closer. (Click here to download this tutorial's source code.) Categories: VB | Tutorial | DirectX |


