Searching data at high speed
Posted on 2005-04-25
I got a tough one for you guys out there, let's first start out with what my application is supposed to do.
My application acts as a barrier between a game server and player clients. It forwards all packages to the player so it can adjust the data on demand, everything is in UDP and for the server not to get confused for EACH player there has to be made a new socket on a new port. It requires reconizing technique's, at first i used a LIST ... which was not fast enough. Then i used a Database which AGAIN did not search fast enough, the thing is here: 'The server sends several dozen packages per second ... between 20-50 packages per second' for each package comming from the server the IP and Index of the socket the data has to be send to can be found easily by using a TAG in the winsocket. But when getting the data from a player (all players send their data to one main socket which they think is the server) the Index of the winsock which sends the data to the server has to be found. This has to happen at each package, and when not happening fast enough the client/server discards them as lost. Resulting in major lag and getting kicked from the server....
Here's a little piece of code to show you the situation. What i am looking for is an extremely fast search method that will do the trick ...
<----- Socket Code with Searching (FindIt2 is a seperate function to search in the database) ----->
If Index = 0 Then
'Main Server where does it originate from?
If Left$(Hexer, 8) = "00000000" Then
Winsock2(1).RemoteHost = "127.0.0.1"
Winsock2(1).RemotePort = 8912
pMes = Winsock2(Index).RemoteHostIP
pMesP = Winsock2(Index).RemotePort
Exit Sub '
Dim Datam As Variant
Datam = FindIt2("Ip", Ipe).Socket
If Datam = "" Or Datam = 0 Then GoTo insiderr:
Winsock2(Datam).RemotePort = 8912
Winsock2(Datam).RemoteHost = "127.0.0.1"
'It is not yet in the list
Load Winsock2(Winsock2.UBound + 1)
Data1.Recordset("Ip") = Winsock2(Index).RemoteHostIP
Data1.Recordset("Port") = Winsock2(Index).RemotePort
Data1.Recordset("Socket") = Winsock2.UBound
cPort = cPort + 1
Winsock2(Winsock2.UBound).LocalPort = cPort
Winsock2(Winsock2.UBound).Tag = Winsock2(Index).RemoteHostIP & ":" & Winsock2(Index).RemotePort
Winsock2(Winsock2.UBound).RemoteHost = "127.0.0.1"
Winsock2(Winsock2.UBound).RemotePort = 8912
<-------> FindIt2 function <------->
Public Type FindIt
Ip As String
Socket As Integer
Port As Integer
Name As String
Public Function FindIt2(Section As Variant, Value As Variant, Optional ChangeVal, Optional ChangeSection) As FindIt
On Error Resume Next
frmMain.Data1.RecordSource = "SELECT * FROM [Sup] WHERE [" & Section & "] ='" & Value & "'"
If frmMain.Data1.Recordset.EOF = True Then
If Len(ChangeVal) > 0 And Len(ChangeSection) < 1 Then
frmMain.Data1.Recordset(Section).Value = ChangeVal
If Len(ChangeVal) > 0 And Len(ChangeSection) > 0 Then
frmMain.Data1.Recordset(ChangeSection).Value = ChangeVal
FindIt2.Ip = frmMain.Data1.Recordset("Ip")
FindIt2.Socket = frmMain.Data1.Recordset("Socket")
FindIt2.Port = frmMain.Data1.Recordset("Port")
FindIt2.Name = frmMain.Data1.Recordset("Name")
I hope you guys can find a good and fast solution, remember that this tool will need to handle 18 to 20 players at a time so it has to search over a hundred times per second without loosing too much milliseconds.
Thanks in advance