12-08-2007, 08:07 PM
Completed! Not Tested yet! But I think it works.
By: William
Difficulty: 3/5
Source: http://www.key2heaven.net/Socket2.rar
Thanks to Bhenur for the idea and explanation behind it.
Introduction
Backup your source!
Currently, the movement is handled through the same socket as everything else that sends from the client to the server. This tutorial will add two new sockets. One to the client and one to the server that handles the movement. So the sending delays decreases.
Client Side
Begin with adding a new socket to frmMirage. Name it "Socket2" without the quote tags.
Find:
Below add:
Find:
Replace it with:
Under:
Add this sub:
Under:
Add:
[code]Public Function ConnectToServer2() As Boolean
'****************************************************************
'* WHEN WHO WHAT
'* ---- --- ----
'* 07/12/2005 Shannara Optimized function.
'****************************************************************
Dim Wait As Long
' Check to see if we are already connected, if so just exit
If IsConnected2 Then
ConnectToServer2 = True
Exit Function
End If
Wait = GetTickCount
With frmMirage.Socket2
.Close
.Connect
End With
' Wait until connected or 3 seconds have passed and report the server being down
Do While (Not IsConnected2) And (GetTickCount = Player(Index).DataTimer + 1000 Then
Player(Index).DataTimer = GetTickCount
Player(Index).DataBytes = 0
Player(Index).DataPackets = 0
Exit Sub
End If
' Check for data flooding
If Player(Index).DataBytes > 1000 And GetPlayerAccess(Index)
By: William
Difficulty: 3/5
Source: http://www.key2heaven.net/Socket2.rar
Thanks to Bhenur for the idea and explanation behind it.
Introduction
Backup your source!
Currently, the movement is handled through the same socket as everything else that sends from the client to the server. This tutorial will add two new sockets. One to the client and one to the server that handles the movement. So the sending delays decreases.
Client Side
Begin with adding a new socket to frmMirage. Name it "Socket2" without the quote tags.
Find:
Code:
frmMirage.Socket.RemoteHost = GAME_IP
frmMirage.Socket.RemotePort = GAME_PORT
Code:
frmMirage.Socket2.RemoteHost = GAME_IP
frmMirage.Socket2.RemotePort = GAME_PORT2
Code:
Sub TcpDestroy()
frmMirage.Socket.Close
Code:
Sub TcpDestroy()
frmMirage.Socket.Close
frmMirage.Socket2.Close
Code:
Sub IncomingData(ByVal DataLength As Long)
Code:
Sub IncomingData2(ByVal DataLength As Long)
Dim Buffer As String
Dim Packet As String
Dim top As String * 3
Dim Start As Integer
frmMirage.Socket2.GetData Buffer, vbString, DataLength
PlayerBuffer = PlayerBuffer & Buffer
Start = InStr(PlayerBuffer, END_CHAR)
Do While Start > 0
Packet = Mid(PlayerBuffer, 1, Start - 1)
PlayerBuffer = Mid(PlayerBuffer, Start + 1, Len(PlayerBuffer))
Start = InStr(PlayerBuffer, END_CHAR)
If Len(Packet) > 0 Then
Call HandleData(Packet)
End If
Loop
End Sub
Code:
Public Function ConnectToServer() As Boolean
[code]Public Function ConnectToServer2() As Boolean
'****************************************************************
'* WHEN WHO WHAT
'* ---- --- ----
'* 07/12/2005 Shannara Optimized function.
'****************************************************************
Dim Wait As Long
' Check to see if we are already connected, if so just exit
If IsConnected2 Then
ConnectToServer2 = True
Exit Function
End If
Wait = GetTickCount
With frmMirage.Socket2
.Close
.Connect
End With
' Wait until connected or 3 seconds have passed and report the server being down
Do While (Not IsConnected2) And (GetTickCount = Player(Index).DataTimer + 1000 Then
Player(Index).DataTimer = GetTickCount
Player(Index).DataBytes = 0
Player(Index).DataPackets = 0
Exit Sub
End If
' Check for data flooding
If Player(Index).DataBytes > 1000 And GetPlayerAccess(Index)