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

[REQUEST] Server-client communication tutorial


Tic Tac 2
 Share

Recommended Posts

I'm not familiar with how to make the server and client communicate, e.g server telling client to do something, or client sending information to server.

I don't know how it's structured and i think this would help not only me, but a lot of other people.
Link to comment
Share on other sites

Its really simple…

I will show you example how to send message from server to client and open it in message box.

This is working for eclipse origins.

SERVER

In monEnumerations in enum ServerPackets we will add new packet SSomething

Now in modServerTCP we will add sub:

```
Sub SendMessageToPlayer(ByVal index as Long,ByVal msg as String)
Dim buffer as clsBuffer
Set buffer = New clsBuffer
buffer.writelong SSomething
buffer.writestring msg
senddatato index,buffer.toarray
set buffer = nothing
end sub

```
Here we write a string and packet and send it to player (index)

So when you want to send message write this 

```
SendMessageToPlayer index,"Hello Eclipse bla bla"

```
Now we need client side to read the message and show it in message box.

In monEnumerations in enum ServerPackets  add  SSomething

in modHandleData in sub initMessages on the bottom add:

```
HandleDataSub(SSomething) = GetAddress(AddressOf HandlePlayerMessage)

```
now in the same module add :

```
Sub HandlePlayerMessage (ByVal index as long,byref data() as byte,byval Startaddr as long,byval extravar as long)

dim msg as string
dim buffer as clsbuffer
set buffer = new clsbuffer
buffer.writebytes data
msg = buffer.readstring

msgbox(msg)

set buffer = nothing
end sub

```
Here we will write data we got and read message from it, then show msgbox with new msg.

You can do much more this is one of the easiest.
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...