Archived

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

Graham

DirectPlay - Specifying IP, and BYTE buffers

Recommended Posts

Currently I have a working DirectPlay8 application. But the only way I can connect to the host is by using the DPNCONNECT_OKTOQUERYFORADDRESSING flag in the Connect() function. This causes a popup box, to show up and ask for the ip address and port you want to connect to. What can I do in code to specify the ip I want to connect to, because the popup causes my game to freeze in fullscreen mode. My current connect function looks like this:
////////////////////////////
	// Connect
	//////////////////////
	hRet = DPlay.g_pDP->Connect( &dpnAppDesc,				// pdnAppDesc
								 DPlay.g_pDeviceAddress,		// pHostAddr
								 DPlay.g_pDeviceAddress,	// pDeviceInfo
							 	 NULL,						// pdnSecurity
					 			 NULL,						// pdnCredentials
			  					 NULL, 0,					// pvUserConnectData/Size
								 NULL,						// pvPlayerContext
								 NULL,						// pvAsyncContext
								 NULL,						// pvAsyncHandle
								 DPNCONNECT_SYNC | 
								 DPNCONNECT_OKTOQUERYFORADDRESSING);// dwFlags
 
Also in DirectPlay8 you can only send BYTE buffers, are there any functions that I can use to easily convert floats and integers into BYTE''s. What if I want to send an object of a class. Thanks Go on an Intense Rampage

Share this post


Link to post
Share on other sites
You should look at the DirectPlay code of the SDKsamples.
Even looking in the SDKdocs would help:

quote:
DirectX document -> DirectPlay -> DirectPlay C++ Tutorials -> Tutorial 4: Connecting to a Session
    DPN_APPLICATION_DESC        dpnAppDesc;
IDirectPlay8Address* pHostAddress = NULL;
.
.
.
ZeroMemory(&dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpnAppDesc.guidApplication = g_guidApp;
.
.
.
hr = g_pDP->Connect(&dpnAppDesc, // Application Description

pHostAddress, // Host Address

g_pDeviceAddress,
NULL,
NULL,
NULL, 0,
NULL,
NULL,
NULL,
DPNCONNECT_SYNC);

if( FAILED( hr))
//Failed Connecting to Host

}




--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..

Share this post


Link to post
Share on other sites
As for the BYTE buffers.. If you want to send a class object you''ll have to write a method for the class that writes its data to the BYTE buffer, and then another method to rebuild a class object from a BYTE buffer.

If you already have a file system its a good idea to derive the file and net buffer classes from a common base class. That way, if you already have code for saving and loading your classes, all you need to write is the net buffer class.

e.g,.

class AbstractFile
{
public:
virtual void Write(...) = 0;
virtual void Read(...) = 0;
};

class File : public AbstractFile
{
public:
//implement the Write and Read methods
};

class NetBuffer : public AbstractFile
{
public:
//implement the Write and Read methods
};

class SomeClassYouWantToSaveAndSendOverTheNetwork
{
public:
void Save(AbstractFile & file);
void Load(AbstractFile & file);
};

Get the idea?

Share this post


Link to post
Share on other sites
I understand by what you mean with the BYTE buffers. I just have to now find a way to convert floats to bytes. As for the Connect() function, im still having difficulties. In your code example your hostaddress is null in the connect function. This will cause an error in the connect function. How do you assign an ip to connect to. The only way I can get around this is to use the local g_pDeviceAddress, as the host address also, and using the DPNCONNECT_OKTOQUERYFORADDRESSING flag.

Just want to know how to connect to a known IP.

Go on an Intense Rampage

[edited by - Graham on October 23, 2003 11:57:41 AM]

[edited by - Graham on October 23, 2003 4:49:57 PM]

Share this post


Link to post
Share on other sites
I am not sure if this answers your question entirely, but as far as specifying the ip in code, you need to use IDirectPlay8Address::BuildFromURLA to construct the address for the host. I think that is correct(been a while since I did this). Or if you are on an LAN you can use EnumHosts to build a list of hosts on the LAN and select one from that list. As far as sending floats and integers, remember it wants a BYTE pointer, so the following would work to convert it.

int iNum;
int fNum;

(BYTE*)&iNum
(BYTE*)&fNum

Hope that helps man.




Share this post


Link to post
Share on other sites