การใช้ directplay ของ DirectX
ผมเขียนโปรแกรม คุยกัน โดยใช้ DirectX 8 อยากทราบวิธีการตรวจสอบโฮสปลายทางว่ามีอยู่จริงหรือเปล่า ถ้ามีอยู่จริงมันไม่มีปัญหาครับ แต่ถ้าHost ไม่มีอยู่จริงเนี่ยอะครับคือปัญหา ช่วยหน่อยน๊ะครับ โครตที่ใช้ติดต่อ --------------------------------------------------- 'Try to connect to the host 'Make sure we're ready to connect Cleanup InitDPlay NetWorkForm.cmdCall.Enabled = False gfHost = False 'Register the Message Handler dpp.RegisterMessageHandler MsgForm 'Set the peer info oPlayer.lInfoFlags = DPNINFO_NAME oPlayer.Name = gsUserName dpp.SetPeerInfo oPlayer, DPNOP_SYNC 'Now try to enum hosts 'Create an address Set dpa = dx.DirectPlayAddressCreate 'We will only be connecting via TCP/IP dpa.SetSP DP8SP_TCPIP dpa.AddComponentString DPN_KEY_HOSTNAME, sHost 'We will try to connect to this host dpa.AddComponentLong DPN_KEY_PORT, glDefaultPort
Set dpl = dx.DirectPlayAddressCreate 'We will only be connecting via TCP/IP dpl.SetSP DP8SP_TCPIP 'First set up our application description With oAppDesc .guidApplication = AppGuid End With 'Try to connect to this host ' On Error GoTo Xerror: DoSleep 500 'Give a slight pause to clean up any loose ends dpp.Connect oAppDesc, dpa, dpl, DPNHOST_OKTOQUERYFORADDRESSING, ByVal 0&, 0 ' dpp.Connect oAppDesc, dpa, dpl, DPNCONNECT_SYNC, ByVal 0&, 0 ' MsgBox dpp.GetCountPlayersAndGroups(DPNENUM_PLAYERS) 'Xerror: If Err.Number <> 0 Then 'Woah, an error MsgBox "ติดต่อมะได้", vbOKOnly Or vbInformation, "แจ้งไม่มี Host" StartHosting MsgForm End If Set dpa = Nothing Set dpl = Nothing
|