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.

DarkBASIC Professional Discussion / DarkNET (Packets)

Author
Message
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 12th Jun 2012 22:46
Hey everybody. Got an app and added Darknet just fine. At least the starting and of a host and connection of clients. Now I'm at actual data traffic.

I've set-up my packets correctly and it seems to work. But the send and received packets must be in order to work properly. Now my game uses a world that loads (unspecified*) additional objects during play, so I'm wondering if there is a way to 'mark' the packet so it can easily be recognized on the other end.

In other words, I need to make the list and order of the sending and receiving of packets dynamic.

* Procedural World Generation

Any suggestions here would be awasome! Thanks!

Kenneth

Regards Sph!nx
http://www.mental-image.net
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 12th Jun 2012 23:06
Quote: "I need to make the list and order of the sending and receiving of packets dynamic."


I am not 100% sure of what you need, but I think what you need to do is send packets that describe what they are for, then act according to the purpose of a received packet.

We could talk all day about how to go about these things. I do not want to tell you that my way is the best, it is just what I find comfortable. There are many ways to go about this, and I am sure other people will give you their own advice; but what I would do is send memblocks in your packets; furthermore the memblocks I send are arrays converted to memblocks, arrays that are of a user defined type (UDT).

What I tend to do is write a number on the first byte of the packet which tells the recipient what UDT array is about to be read.

Examples exposed for clarity:

mn Add Byte PacketId, OBJECT_LOADING_TASKS
TASKS would be a number between 0 and 255, so I have up to 256 different types of arrays that I could send

The next 4 bytes contain a integer value which represents the size of the following memblock in bytes.

Make Memblock From Array MemblockId, ArrayName()
mn Add Int PacketId, Get Memblock Size( MemblockId)


Once you have the type of array and size of the memblock; next, read and convert the memblock into the UDT array and do what you must with it on the server or client.

You could also skip using UDT rrays to avoid having to convert to memblocks; but I find it easier to work with than a series of values in memblocks directly.

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 12th Jun 2012 23:21 Edited at: 12th Jun 2012 23:24
Thanks for the quick reply. So basically I'm sending additional data in the packet to identify what it is?

Example: I send a string packet that contains the position of the object, but also identifies the object. "obj1+xpos=10+ypos=99+zpos=25" (Object 1 and all coordinates of new position)

This makes it possible to make the order random. I could use the first packed send to set the amount of packets send after that one.

I think I got it now, though I need to experiment a bit with this!

Thanks Chris Tate!

Regards Sph!nx
http://www.mental-image.net
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 13th Jun 2012 00:10
Quite right, however your string packet is too large for a network intensive game. If it is a network intensive game, I'd avoid using strings. That string there is 29 bytes in size, but you can use 16 bytes to send 3 floating point values representing the location of the object. And one integer representing the object Id.

Although somewhat twice as large and twice as laggy, your idea would still work.

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 13th Jun 2012 00:37 Edited at: 13th Jun 2012 00:39
Alight... Haven't considered that. I need to send a lot of data.

The game I'm building is a multi-player space shooter in a procedurally generated galaxy. The more the player explores the galaxy the more the galaxy will grow. This galaxy is server side.

So the players need to receive all generated objects (and their data) upon entering the server and players need to be updated on everything.

I will experiment with your suggestions. Thanks again! I hope I'm not to bold, but would you mind posting a little snippet of how you handle the packets?

Regards Sph!nx
http://www.mental-image.net
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 14th Jun 2012 03:40
Tagging in

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 14th Jun 2012 16:11
What do you mean by 'tagging in'?

I figured I would make an array, convert array to memblock, memblock to packet, encrypt packed, send packet.

The receiver would then reverse that process. Sound good?

Regards Sph!nx
http://www.mental-image.net
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th Jun 2012 02:37 Edited at: 15th Jun 2012 02:37
Quote: "What do you mean by 'tagging in'?"


silently joining the discussion

EDIT

Fixed endquote and quote message

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 15th Jun 2012 14:04 Edited at: 15th Jun 2012 14:06
Ah yes. You are welcome ofcourse!

I'm still experimenting on different ways of processing the packet 'streams' to clients under different conditions (new players, current 'playing', etc.)

One thing lacking in the documentation is more information on assembling packets, encryption, etc. The receiver must know the bytesize of the packet. I need to create a system where the server could send data without knowing the actual bytesizes and a way to calculate it on the receiving end.

I need this because; the amount of packets and it's content cannot be predetermined by the receiver... I do have an idea of handling the amount of packets, but it's the byte-sizes I'm still having trouble with.

Any suggestions here?

Regards Sph!nx
http://www.mental-image.net
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th Jun 2012 14:26
basjak helped mention something about msn set auro rcv size will look into it unless someone [basjak] betas me to it or anyone else i got an important meeting to rush off to back soon!

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 15th Jun 2012 16:50 Edited at: 15th Jun 2012 16:50
Thanks!

Another question;
The Cube example shows that it works with a single instance. I took that as well and am trying to create condition where different flows of data goes to different clients (a new client, still needing to load the game or a currently playing client).

Wouldn't it be much easier if I use more instances for different data 'streams'?

Regards Sph!nx
www.mental-image.net
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th Jun 2012 18:35 Edited at: 15th Jun 2012 18:36
http://forum.thegamecreators.com/?m=forum_view&t=135855&b=5&msg=2359262#m2359262

here you go it was

Quote: "-mn set auto resize TCP instanceno, clientno, autoflag"


according to awesome basjak

I am not used to instances and when I played with it it would not work... perhaps jump onto that thread you will likely get more responses! oh and remember to link them back to this thread so you can have a choice of continuing the debate here or there...

EDIT

Oh and the meeting went fantastic

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 15th Jun 2012 21:12
Sorry I think am late.

About UDP it's advisable to keep packet size constant for safe delivery.

If you are about to change the same packet size very often then you are better off with TCP.

After a client is created at client side, use the command:
mn set auto resize TCP instanceno, clientno, autoflag.

[quote]According to awesome basjak[\quote]
Lol. You refueled my energy after a long day

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 15th Jun 2012 22:41
You guys rule!

So, if I understand correctly, that commands resizes it? I figure that it would fill up the packet until it reaches a certain size?

Anyways, I'll give it a go!

Regards Sph!nx
www.mental-image.net
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 15th Jun 2012 23:13
Remember to keep your UDP packets the same size.

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 15th Jun 2012 23:18 Edited at: 15th Jun 2012 23:24
Thanks, I will!

Quote: "If you are about to change the same packet size very often then you are better off with TCP."


About TCP. I've read the slow, reliable TCP vs the fast, unreliable UDP. I intend to use main game statistics, chat, important strings (like server name), etc. as TCP. I will use UDP for object positioning and control inputs. Sounds good?

Edit:
Still I wonder how I would set it up if the amount of objects, thus data, will grow during gameplay. I use a procedural generated galaxy, that gets generated during gameplay. Any suggestions?

Regards Sph!nx
www.mental-image.net
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 16th Jun 2012 00:44
Then, you you use: mn send all tcp. To tell the other computers to create extra object. The amount of grown data must have a limit at last to avoid slowing down the system. So try to put all in 1 packet. For example a packet of 1024byte can store information for about 20 object.

In the end try different technics to see when you can keep you game speed stable. For growing game data, few TCPs will not be very harmful.

However, the term ' growing game data ' depends on what data you mean. If it is entities, then I think its fine but if is about number of players joining, then I think you will stuck between 16 to 32 players.

It's all about what you're doing with you game.

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 16th Jun 2012 17:47
Thanks for the info!

Well, the idea is that during gameplay more of the galaxy will be explored so the total pool of objects will grow.

Though my game has nothing to do with blocks or anything, best example is Minecraft. Players explore world and more blocks (objects) will be added to the total pool of objects.

I know I can limit the data by doing some client side procedural generation but, like minecraft, I will have players be able to influence the objects (settings, positions) and add additional objects to the game.

Regards Sph!nx
www.mental-image.net
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 16th Jun 2012 17:51
have a look at these two link. it may be an outstanding solution for your game.

http://www.thegamecreators.com/?m=view_product&id=2311

http://www.thegamecreators.com/?m=view_product&id=2293

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 16th Jun 2012 17:57 Edited at: 16th Jun 2012 19:40
Thanks, I already have both of those and intent to use them. Though I will only use them client side for rendering and stuff.

What I need to communicate through the packets is the list of objects and their settings for new players.

For 'already playing' players I need to send the list of objects and their new/updated settings (like positions, etc.)

The problem I'm facing now is, that the list of game objects will grow during gameplay because the more the players explore, the more the game world will grow.

Edit :
Alright, here is my Idea. Just a plan that I will experiment with.

TCP
Nieuw players/clients receive the main settings of the server/game. The players receive the amount of objects (per type) that are currently in the current "object pool".* Also, when the "object pool" is updated (Object is added or removed), players are being updated through TCP.

Chat and other major game statistics go through TCP.

UDP
Players/clients receive all updates from all objects in the object pool (The exact amount is set through tcp).
Players/Clients will send their control input through UDP.

* Object pool: The amount of objects is

How does this sound? Mind you, I'm a slow coder but I will post my findings here!!

Regards Sph!nx
www.mental-image.net
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 16th Jun 2012 20:28 Edited at: 16th Jun 2012 20:30
Quote: "slow coder"

don't worry. it will always be when creating new things.

what you've mentioned sounds good.

you should not worry about the expanding galaxy and using the mentioned pluggins will not render out of camera objects.

Quote: "How does this sound? Mind you, I'm a slow coder but I will post my findings here!!"


can't wait. we're all started from this forum. I myself owe this forum a lot and take it happily prsonal.

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 16th Jun 2012 20:41
Quote: "you should not worry about the expanding galaxy and using the mentioned pluggins will not render out of camera objects."

Yeah, also it is purely client size and is rendering.

Like I said, it's the data that needs to be communicated. That is the real challenge and needs lot's of experimentation on my part.

Anyways, thanks all for your support so far! I've learned a whole lot more about TCP and UDP packets.

Regards Sph!nx
www.mental-image.net
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 18th Jun 2012 20:01
Alright, I can send a message (TCP) to a newly joined player, however, sending a message back is givving me errors.

Server Code: (Part of the update function)


Client Code: (Part of the update function)


Probably because it is using sending and receiving at the same time... just a guess though. Any suggestions?

Thanks!

Regards Sph!nx
www.mental-image.net
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 19th Jun 2012 22:54
-Bump-

I know, I know... impatient. I could really use some feedback.

Regards Sph!nx
www.mental-image.net
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 20th Jun 2012 21:52
Ok, I've fixed it and I've got connection and packets UDP/TCP working fine. I dumped my old code, started over with the cube example as my guide.

Regards Sph!nx
www.mental-image.net
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 21st Jun 2012 02:16
Just looked at your code. At least am sure now you figured out your mistake.

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 21st Jun 2012 16:40
Yeah I know the problem. The receiving and sending ran at the same time in the loop under the same sort of conditions. I now have the sending and receiving of packets separated and it works perfectly now.

Regards Sph!nx
www.mental-image.net
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 21st Jun 2012 18:21
Cool

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 24th Jun 2012 15:37
Yeah, working like a charm. To close of this thread... Thanks all! Your input was a great help and motivator!

Regards Sph!nx
www.mental-image.net

Login to post a reply

Server time is: 2026-07-08 00:25:29
Your offset time is: 2026-07-08 00:25:29