Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

TCP Question


WeedDealer
 Share

Recommended Posts

I've been messing around with the source tring to find out how it works.And i have seen that when u send data from client to server it use clsBuffer.If somebody can explain me why clsbuffers when it could send data as string or long to server I would be gratefull.
Link to comment
Share on other sites

Basically the Buffer (cls is just a naming convention) packs all the data into a sendable format, writes how long each piece of data is and sends it off to the server. The server will then begin reading and unpacking it. The point of using the Buffer is that you can send lots of different data with different types e.g:

```

Buffer.WriteString Player.Name

Buffer.WriteByte Player.Age

Buffer.WriteLong Player.X

Buffer.WriteLong Player.Y

```

And the server is able to read this. It's a lot faster than sending data one by one and a lot more flexible.
Link to comment
Share on other sites

A typical packet looks like this:

```
Public Sub SendLogin(ByVal name As String, Pass As String)

Dim buffer As clsBuffer

Set buffer = New clsBuffer

buffer.WriteLong CLogin

buffer.WriteString name

buffer.WriteString Pass

SendData buffer.ToArray()

Set buffer = Nothing

End Sub
```

Let's break it down.

```
Set Buffer = New clsBuffer
```

This is part of Object Orientated programming. It basically creates a new instance of the Buffer class so we can use it.

```

buffer.WriteLong CLogin

buffer.WriteString name

buffer.WriteString Pass

```

These lines add the various pieces of data to the Buffer. "CLogin" is a header that allows to server to know how to unpack the data and how to handle it (i.e. which sub to use).

```

SendData buffer.ToArray()

Set buffer = Nothing

```

Finally we send all the packet data to the server. "Set Buffer = Nothing" simply removes the Buffer class we just used from memory.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...