Thread: Protocol Parser?
March 21st, 2009, 07:51 PM #1
I'm trying to create a server for a game i've been programming for a while, the problem is what is the most efficient way to parse the data and answer correctly?
I mean a smiple if else is good enough if you dont have more than 20 commands, but imagine a protocol with more than 100? scanning through 100 if else is probably slowing the sever down^^
any good ideas?
March 21st, 2009, 08:13 PM #2
- Join Date
- Oct 2001
depends entirely on your language of choice
each language has their own methods of indexed arrays
Regardless each language typically has a hash method
I know in vbs its called a dictionary, I think in Ruby it has the same name.
basically you dont want to use some crappy bubble sort, so a dictionary is a builtin method to do fast scans for specific data.
so read protocol command
lookup command in dictionary
returns value of requisite function call
March 21st, 2009, 08:37 PM #3
the looking up part is where i have my problems, because every method i found so far is as slow as a simple "if else" chain (like switch, hashtable etc.)
i'm using java btw
March 22nd, 2009, 08:43 AM #4
If your data is sorted, a binary search is going to be about your fastest method. Binary tree is nice for unsorted data.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
By Felonist in forum General Tech DiscussionReplies: 3Last Post: January 1st, 2009, 11:16 AM
By taclandude in forum Networking and InternetReplies: 1Last Post: October 14th, 2004, 10:46 AM
By jinsta in forum Applications and Operating SystemsReplies: 2Last Post: February 10th, 2004, 02:42 AM
By LiLRiceBoi in forum Networking and InternetReplies: 2Last Post: July 27th, 2002, 02:24 PM
By ekl in forum Networking and InternetReplies: 1Last Post: May 13th, 2002, 06:14 PM