// my message structs
struct netmsg
{
int type;
};
struct netmsg_position : public netmsg
{
int x,y;
};
// message types
enum messagetype { msgtype_position = 0, msgtype_message = 1 };
// function that send a message
void myengine::net::client::send(netmsg msg,int msgsize)
{
if(m_connected)
{
DPNHANDLE handle;
// description
DPN_BUFFER_DESC desc;
desc.dwBufferSize = msgsize;
desc.pBufferData = (BYTE*)&msg
// send
m_dpclient->Send(&desc,1,0,NULL,NULL,DPNSEND_SYNC |
DPNSEND_GUARANTEED | DPNSEND_NOCOPY | DPNSEND_NOLOOPBACK);
}
}
// send a message
netmsg_position pos;
pos.type = msgtype_position;
pos.x = 23;
pos.y = 19;
m_client->send(msg,sizeof(netmsg_message));
// inside message handler for server
case DPN_MSGID_RECEIVE:
// message received
PDPNMSG_RECEIVE data = (PDPNMSG_RECEIVE)msg_buffer;
netmsg *msg = (netmsg*)data->pReceiveData;
((server*)user_context)->on_client_receive(msg->type,data->pReceiveData);
return S_OK;
// function that handles message
void myengine::net::server::on_client_receive(int msgtype,PBYTE msg)
{
if(msgtype == msgtype_position)
{
netmsg_position *pos = (netmsg_position*)msg;
dosomething(pos);
}
else if(msgtype == msgtype_message)
{
netmsg_message *mess = (netmsg_message*)msg;
dosomething(mess);
}
}
Thanks in advance for any help I can get.
Getting corrupt data from directplay
Hi!
I got a problem when sending directplay messages. Everything works great when I send a message of type ''netmsg''. But when I''m about to send a message of type ''netmsg_position'' for example, some of the data in the struct is corrupt.
I don''t think there is something wrong with directplay, I''m sure that I screw up somewhere with the pointers or something.
Below is some of my source code for you to check out.
ummm...,
shouldn''t m_client->send(msg,sizeof(netmsg_message));
be m_client->send(pos,sizeof(netmsg_position)); ?
shouldn''t m_client->send(msg,sizeof(netmsg_message));
be m_client->send(pos,sizeof(netmsg_position)); ?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement