Register for your free account! | Forgot your password?

You last visited: Today at 20:14

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



PacketBuilder

Discussion on PacketBuilder within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
Arco.'s Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
PacketBuilder

Alrighty, well I made this packetbuilder, I feel as if it can be improved though. Anyone have any ideas, any suggestions etc?
Arco. is offline  
Old 12/01/2011, 00:16   #2


 
CptSky's Avatar
 
elite*gold: 0
Join Date: Jan 2008
Posts: 1,443
Received Thanks: 1,175
Quote:
Originally Posted by Arco. View Post
Alrighty, well I made this packetbuilder, I feel as if it can be improved though. Anyone have any ideas, any suggestions etc?[...]
Seems really similar to the one I did for you. But, you need to free the memory and everything... Take a look at what I did. You'll be able to improve it. Oh, and as I said when I did the builder for you, you should use structures and pointers to them, it's faster.

If you no longer have mine.
CptSky is offline  
Thanks
3 Users
Old 12/01/2011, 04:52   #3
 
Arco.'s Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
Quote:
Originally Posted by CptSky View Post
Seems really similar to the one I did for you. But, you need to free the memory and everything... Take a look at what I did. You'll be able to improve it. Oh, and as I said when I did the builder for you, you should use structures and pointers to them, it's faster.

If you no longer have mine.
Yeah, the one you made, I took that and read it over, learned about pointers, and used it as a reference to make a builder. Simplified it a good bit, also explicitly declare offsets, return a ByteArray. Thanks to your builder, I learned a good bit about pointers <3
Arco. is offline  
Old 12/01/2011, 06:27   #4
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 920
Even better - pin the byte pointer so it's not swiped by the GC, and assign the internal pointer in the "packet" base class to the pointer to the byte array in a constructor *for packets to process* with the finalizer always freeing the unmanaged memory. Write a bunch of functions in the packet class to split up the fields by pointer arithmetic, derive all packets off of the packet class, and in these derived classes, use accessors to use the base class read and write functions. Tada, you're using just a tiny bit more memory and have a very slight performance degrade for 1028739x neater and more flexible packet handling than pointers to structures.

I've done all this except pinning the byte pointer and assigning it for processing packets (right now, we're copying the data over with memcpy... but hey, I'm never satisfied so what the hell), but there's probably something stupidly wrong with doing this... Now I'm going to go implement that. I'll let you know if what I said works or not. If someone knows it does/doesn't work, please tell me before I start wasting time. ;d
Lateralus is offline  
Thanks
1 User
Old 12/01/2011, 15:05   #5
 
miketheking's Avatar
 
elite*gold: 0
Join Date: Oct 2009
Posts: 63
Received Thanks: 10
i just realised that my packetbuilder is ****
miketheking is offline  
Old 12/01/2011, 20:46   #6
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,282
Received Thanks: 4,191
I don't use a packet builder. I make them using structs and send them to the client in one line of code. I never have to copy it... or process it... or waste processor time doing comparisons in the wrapper.
Spirited is offline  
Old 12/01/2011, 20:52   #7
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 920
Quote:
Originally Posted by Fаng View Post
I don't use a packet builder. I make them using structs and send them to the client in one line of code. I never have to copy it... or process it... or waste processor time doing comparisons in the wrapper.
Doing it that way is ugly, time consuming, and not very object oriented.
Lateralus is offline  
Old 12/01/2011, 21:03   #8
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,282
Received Thanks: 4,191
Quote:
Originally Posted by Lateralus View Post
Doing it that way is ugly, time consuming, and not very object oriented.
Lol, if you say so o.o
I personally think it's much more organized than anything else I've seen. In addition to that, it's much faster than traditional packet building. I've tested it. =p
Spirited is offline  
Old 12/01/2011, 21:23   #9
 
Arco.'s Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
Quote:
Originally Posted by Fаng View Post
Lol, if you say so o.o
I personally think it's much more organized than anything else I've seen. In addition to that, it's much faster than traditional packet building. I've tested it. =p
Cause you've used every single method of packetbuilding known to man right?
Forgot, Fang is pro coder, my bad.
Arco. is offline  
Old 12/01/2011, 21:46   #10
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,282
Received Thanks: 4,191
Quote:
Originally Posted by Arco. View Post
Cause you've used every single method of packetbuilding known to man right?
Forgot, Fang is pro coder, my bad.
Yes Arco. I actually have used every possible *good* and base way to code a packet in C#. It's called experience.
Spirited is offline  
Old 12/01/2011, 22:20   #11
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 920
Quote:
Originally Posted by Fаng View Post
Lol, if you say so o.o
I personally think it's much more organized than anything else I've seen. In addition to that, it's much faster than traditional packet building. I've tested it. =p
How is your method "much faster" than mine? Using pointers to structures has exactly the same function as my packet class, except mine is much more flexible and object oriented. I'm pretty sure small accessors are inlined in my case, so what I have is unsafe code only in the packet class and beautiful code in the derived classes and everywhere that uses them that has the same performance as, if not faster than, your method, is much easier to work with, and follows proper OOP guidelines - not an opinion.
Lateralus is offline  
Thanks
3 Users
Old 12/01/2011, 22:40   #12
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,282
Received Thanks: 4,191
Quote:
Originally Posted by Lateralus View Post
How is your method "much faster" than mine? Using pointers to structures has exactly the same function as my packet class, except mine is much more flexible and object oriented. I'm pretty sure small accessors are inlined in my case, so what I have is unsafe code only in the packet class and beautiful code in the derived classes and everywhere that uses them that has the same performance as, if not faster than, your method, is much easier to work with, and follows proper OOP guidelines - not an opinion.
I was comparing it to traditional packet building. You don't have any stupid comparisons like Impulse's wrapper does. It should be fine. And as far as a difference between structs and pointer wrappers like yours... there is no difference (performance wise). I honestly like structs better. It's just a preference of mine.

Edit: Jack says there probably is a difference between structs and wrappers like yours - but it's so small that it wouldn't make a big difference.
Spirited is offline  
Old 12/01/2011, 23:02   #13
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 920
Quote:
Originally Posted by Fаng View Post
Edit: Jack says there probably is a difference between structs and wrappers like yours - but it's so small that it wouldn't make a big difference.
If the compiler inlines small functions and accessors like mine, then there isn't a difference. As of right now, because I copy packets with memcpy into the internal pointer, yeah, there's a difference.
Lateralus is offline  
Old 12/03/2011, 23:30   #14
 
elite*gold: 0
Join Date: Oct 2009
Posts: 31
Received Thanks: 1
I know this is stupid question but what exactly is a packetBuilder?
mateo136 is offline  
Old 12/03/2011, 23:43   #15


 
KraHen's Avatar
 
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
PHP Code:
public static byte[] Serialize(object Data)
        {
            
int size Marshal.SizeOf(Data);
            
byte[] bdata = new byte[size];
            
GCHandle handle GCHandle.Alloc(bdataGCHandleType.Pinned);
            
Marshal.StructureToPtr(Datahandle.AddrOfPinnedObject(), false);
            
handle.Free();
            return 
bdata;
        } 
KraHen is offline  
Reply


Similar Threads Similar Threads
Packetbuilder
10/21/2011 - CO2 Programming - 18 Replies
I have a simple packetbuilder right now, but is there any way that this can be optimized for efficiency? class PacketBuilder { private byte buffer; public PacketBuilder(byte Buffer) { buffer = Buffer; } public void ZeroFill(byte Buffer, ushort Offset, ushort Count) {
Packetbuilder
10/13/2011 - General Coding - 0 Replies
I have a simple packetbuilder right now, but is there any way that this can be optimized for efficiency? class PacketBuilder { private byte buffer; public PacketBuilder(byte Buffer) { buffer = Buffer; } public void ZeroFill(byte Buffer, ushort Offset, ushort Count) {



All times are GMT +1. The time now is 20:15.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.