Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / C++ DGK: DarkNet: ? - Newby Question how does DarkNet know what is being set and received?

Author
Message
Timidon
19
Years of Service
User Offline
Joined: 26th Jun 2005
Location: Bakersfield, Ca. USA.
Posted: 9th Sep 2009 00:56
I am working on understanding DarkNet by Micheal P.

I am using the Advanced Cube World demo as the ground work for the sever and client, mostly because they are both there and work side by side.

I am trying to figure out how the system knows what varibles I am trying to get across to other clients the host?

int OperationID // mnAddInt(SendPacket,OperationID);
int Target1 // mnAddInt(SendPacket,Target1);
int Source1; // mnAddInt(SendPacket,sSource1);

mnSendTCPAll(INST_HOST,SendPacket,false,false,CurrentPlayer);

that would send the information from the host to all the players, save the CurrentPlayer, he's the orignator of the packet

But how does the system know that I sent these variables across bitspace? I see in the demo code, allot of transmits and receives. Is there a specific order that these must be read in? that's what got me a bit confused.

This is not really a question of how to do it, but more along the longs of how it's done. Back to poking at code with a really long stick.

There are many answers but just one question" ~ Jerilith the Mad
Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 9th Sep 2009 12:30
Packets have 3 internal variables:

1. Memory size: this is the amount of memory allocated to the packet via mnChangeMemorySize or mnSetMemorySize. The used size can't exceed this.

2. Used size: this is the amount of memory in use. Initially it is 0, but if you add data to it it will increase. mnSendTCP and mnSendUDP will send all data up to the used size.

3. Cursor position: data is inserted at this point. The cursor can be moved anywhere in the packet using mnSetCursor. The cursor is moved forward by the amount of data written or read using an mnAdd or mnGet command.


This example should help:

Lets say I add 3 bytes to a packet, after first using mnSetMemorySize to allocate 5 bytes of memory to the packet.

Initially: Used size = 0, Cursor position = 0, Memory size = 5.

mnAddByte(50): Used size = 1, Cursor position = 1, Memory size = 5.

mnAddByte(12): Used size = 2, Cursor position = 2, Memory size = 5.

mnAddByte(15): Used size = 3, Cursor position = 3, Memory size = 5.


The packet contains 50, 12 and 15 in that order.


If I use mnSetCursor and set the cursor back to 0 (which it was initially) and then use mnAddByte(10) the internal variables look like this: Used size = 3, Cursor position = 1, Memory size = 5 and the data is: 10, 12 and 15 in that order (50 was overwritten).

If your packet looks like this: mnAddFloat, mnAddByte, mnAddInt, you should read it in the same way when the packet is received on the other end: mnGetFloat, mnGetByte, mnGetInt.

When packets are received they are put into a queue and the mnRecv commands get them from a queue. If you are using UDP modes 'per client' or 'per client, per operation' you have to have specific data at the start of the packet (see documentation for more info).

Hope you found that useful

Timidon
19
Years of Service
User Offline
Joined: 26th Jun 2005
Location: Bakersfield, Ca. USA.
Posted: 9th Sep 2009 20:18
Thanks, the explanation is very useful. I am kinda new to the networking aspect. Thanks for putting together the library. It is very helpful. I am just trying to understand it.

I will go give that code bits a poke and see what happens.

There are many answers but just one question" ~ Jerilith the Mad

Login to post a reply

Server time is: 2024-10-01 12:28:45
Your offset time is: 2024-10-01 12:28:45