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

(EO) T�¡P client-server


23.kraft
 Share

Recommended Posts

ModEnumeration
ModClientTCP/ModServerTCP
ModHandleData

Look through those, they all pretty much show how to use the system, if you look thoroughly enough. Again, I'm tired as hell and I'm helping to the best I can without giving myself a gruesome headache. Please be patient and look through what I just pointed at, or if you're too lazy to figure stuff out wait for someone to write a tutorial.
Link to comment
Share on other sites

This is a loaded question; it's hard to dig right in and ask how packets are sent back and forth.

Robin created a very nice custom class which gets used as a buffer when sending packets.  Whenever you're sending data in either direction, you first declare your new buffer as a clsBuffer, then you give it a long variable which defines how the client or server will read the packet and handle it.

Example, let's make a button on frmMain, and send the words 'Hello Server!' to the server and have the server sent a message back to the client!

1\. Create a button on frmMain, call it cmdHello, give it the following backend code
```
dim buffer as clsBuffer 'Setting up the buffer
dim tmpString as String 'tmpString which will hold the 'Hello Server!

tmpString = "Hello Server!" 'See, we now have a string variable defined that we will send..dur...

set buffer = new clsBuffer 'We're now setting it as a new buffer.
buffer.writeLong CSendHelloServer 'This CSendHelloServer is what gets sent 'first and will let the server know what command has been sent
buffer.writeString tmpString 'We're writing the tmpString (Hello Server) to the buffer
SendData buffer.toarray() 'We've actually sent the packet
set buffer = nothing ' Close the buffer

```
Step 2\. Now, if you noticed, we IDed that packet as CSendHelloServer, we put C first because it's coming from the client.  The server won't know what CSendHelloServer means unless we declare it first.  Inside the SERVER and the CLIENT in modEnumerations, where it defines all the client packets add.
```
CSendHelloServer

```
Step 3.  Now we need to make the SERVER handle the data that is being sent.  If you look in modHandleData, the initMessages function.  What we are going to do is add a new Handler for CSendHelloServer, so add this to the bottom of InitMessages.  If you look, we're bascially looking at the packet, noticing it's identified as CSendHelloServer and we're calling the HandleHelloServer Sub!
```
HandleDataSub(CSendHelloServer) = GetAddress(AddressOf HandleHelloServer)

```
Step 4\. We're now going to add the HandleHelloServer sub, add the following new Sub to the bottom of modHandleData on the Server.
```
Sub HandleGetLoot(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
    Dim buffer As clsBuffer 'Declaring the buffer
    Dim tmpString As Long 'Declaring the tmpString that will handle the data we sent

    Set buffer = New clsBuffer 'Setup the buffer
    buffer.WriteBytes Data() 'Write everything!

    tmpString = buffer.ReadString 'Read the String that we wrote

    if tmpString = "Hello Server!" then 'If our Message was Hello Server, say Hi back!
    Call PlayerMsg(index, "Hello Client!", Yellow)
    else 'If our message wasn't Hello Server, make it say What?
    Call PlayerMsg(index, "What?", Yellow)
    end if
    Set buffer = Nothing 'Clear the buffer
End Sub

```
Hope this helps explain the traffic process a bit easier
Link to comment
Share on other sites

gives an error "tmp String = buffer.Read String 'Read the String that we wrote"

clarify sdes "Sub HandleGetLoot (ByVal index As Long, ByRef Data () As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long"

should be so: Sub HandleHelloServer (ByVal index As Long, ByRef Data () As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long "?
Link to comment
Share on other sites

I tried to make myself) but the error "SendData Buffer.ToArray ()" (wrote that the Sub or Function not defined)
I did the following:
i will continue your code called "Hello server!"
I ordered on the server:
0)
SSendHelloServer
1)
Sub HandleHelloServer(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
Dim Buffer As clsBuffer
Dim tmpString As String 
Dim tmpStrin As String
Set Buffer = New clsBuffer
Buffer.WriteBytes Data()

tmpString = Buffer.ReadString

If tmpString = "Hello Server!" Then
tmpStrin = tmpString
Call HandleD(tmpStrin)
Call PlayerMsg(index, "Hello Client!", Yellow)
Else
Call PlayerMsg(index, "What?", Yellow)
End If
Set Buffer = Nothing
End Sub
2)
Sub HandleD(ByRef tmpStrin As String)
Dim Buffer As clsBuffer '
Set Buffer = New clsBuffer
Buffer.WriteLong SSendHelloServer
Buffer.WriteString tmpStrin
SendData Buffer.ToArray()  "Errors are here"
Set Buffer = Nothing ' Close the buffer
End Sub

I ordered on the client:
0)
SSendHelloServer
1)
HandleDataSub (SSendHelloServer) = GetAddress (AddressOf HandleHelloServer)
2)
Sub HandleHelloServer (ByVal index As Long, ByRef Data () As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
  Dim Buffer As clsBuffer
  Dim tmpString As String
  Dim tmpStrin As String
  Set Buffer = New clsBuffer
  Buffer.WriteBytes Data ()

  tmpString = Buffer.ReadString

  If tmpString = "Hello Server!" Then
  frmMain.Command1.Caption = "Hello Server!"
  End If
  Set Buffer = Nothing
  End Sub
I can not understand what the error (
Moderators podpravte as it should but I do not know how)
Link to comment
Share on other sites

@SamuGames:

> This is a loaded question; it's hard to dig right in and ask how packets are sent back and forth.
>
> Robin created a very nice custom class which gets used as a buffer when sending packets.  Whenever you're sending data in either direction, you first declare your new buffer as a clsBuffer, then you give it a long variable which defines how the client or server will read the packet and handle it.
>
> Example, let's make a button on frmMain, and send the words 'Hello Server!' to the server and have the server sent a message back to the client!
>
> 1\. Create a button on frmMain, call it cmdHello, give it the following backend code
> ```
> dim buffer as clsBuffer 'Setting up the buffer
> dim tmpString as String 'tmpString which will hold the 'Hello Server!
>
> tmpString = "Hello Server!" 'See, we now have a string variable defined that we will send..dur...
>
> set buffer = new clsBuffer 'We're now setting it as a new buffer.
> buffer.writeLong CSendHelloServer 'This CSendHelloServer is what gets sent 'first and will let the server know what command has been sent
> buffer.writeString tmpString 'We're writing the tmpString (Hello Server) to the buffer
> SendData buffer.toarray() 'We've actually sent the packet
> set buffer = nothing ' Close the buffer
>
> ```
> Step 2\. Now, if you noticed, we IDed that packet as CSendHelloServer, we put C first because it's coming from the client.  The server won't know what CSendHelloServer means unless we declare it first.  Inside the SERVER and the CLIENT in modEnumerations, where it defines all the client packets add.
> ```
> CSendHelloServer
>
> ```
> Step 3.  Now we need to make the SERVER handle the data that is being sent.  If you look in modHandleData, the initMessages function.  What we are going to do is add a new Handler for CSendHelloServer, so add this to the bottom of InitMessages.  If you look, we're bascially looking at the packet, noticing it's identified as CSendHelloServer and we're calling the HandleHelloServer Sub!
> ```
> HandleDataSub(CSendHelloServer) = GetAddress(AddressOf HandleHelloServer)
>
> ```
> Step 4\. We're now going to add the HandleHelloServer sub, add the following new Sub to the bottom of modHandleData on the Server.
> ```
> Sub HandleGetLoot(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
>     Dim buffer As clsBuffer 'Declaring the buffer
>     Dim tmpString As Long 'Declaring the tmpString that will handle the data we sent
>    
>     Set buffer = New clsBuffer 'Setup the buffer
>     buffer.WriteBytes Data() 'Write everything!
>    
>     tmpString = buffer.ReadString 'Read the String that we wrote
>
>     if tmpString = "Hello Server!" then 'If our Message was Hello Server, say Hi back!
>     Call PlayerMsg(index, "Hello Client!", Yellow)
>     else 'If our message wasn't Hello Server, make it say What?
>     Call PlayerMsg(index, "What?", Yellow)
>     end if
>     Set buffer = Nothing 'Clear the buffer
> End Sub
>
> ```
> Hope this helps explain the traffic process a bit easier

tried the same thing again on the server by setting a button on the server. gives tighter error "" SendData Buffer.ToArray () "(wrote that the Sub or Function not defined)

I ordered on the server:

0)
SSendHelloServer
1)
Private Sub cmdHello_Click ()
Dim buffer As clsBuffer
  Dim tmpString As String

  tmpString = "Hello Server!"

  Set buffer = New clsBuffer
  buffer.WriteLong SSendHelloServer
  buffer.WriteString tmpString
  SendData buffer.ToArray ()
  Set buffer = Nothing
End Sub

I ordered on the client:

0)
SSendHelloServer
1)
HandleDataSub (SSendHelloServer) = GetAddress (AddressOf HandleHelloServer)
2)
Sub HandleHelloServer (ByVal index As Long, ByRef Data () As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
  Dim buffer As clsBuffer
  Dim tmpString As String

  Set buffer = New clsBuffer
  buffer.WriteBytes Data ()

  tmpString = buffer.ReadString

  If tmpString = "Hello Server!" Then
  frmMain.Command2.Visible = True
  End If
  Set buffer = Nothing
  End Sub

who knows how to fix the problem?
Link to comment
Share on other sites

how well I did everything exactly copied (
the only thing I changed is prescribed:
SSendHelloServer (because the packet goes to the client)
instead of
CSendHelloServer
and
HandleDataSub (SSendHelloServer) = GetAddress (AddressOf HandleHelloServer)
instead of
HandleDataSub (СSendHelloServer) = GetAddress (AddressOf HandleHelloServer)
Link to comment
Share on other sites

now shows no errors)
the server:
0)
SSendHelloServer
1)
Private Sub Command1_Click()
Dim buffer As clsBuffer
Dim tmpString As String
Dim index As Long

tmpString = "Hello Server!"

Set buffer = New clsBuffer
buffer.WriteLong SSendHelloServer
buffer.WriteString tmpString
SendDataTo index, buffer.ToArray()
Set buffer = Nothing
End Sub

client:

0)
SSendHelloServer
1)
HandleDataSub(SSendHelloServer) = GetAddress(AddressOf HandleHelloServer)
2)
Sub HandleHelloServer(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
Dim buffer As clsBuffer
Dim tmpString As String

Set buffer = New clsBuffer
buffer.WriteBytes Data()

tmpString = buffer.ReadString

If tmpString = "Hello Server!" Then
frmMain.Command1.Caption = 1
End If
Set buffer = Nothing
End Sub

error does not issue and why it does not work (
Who knows the reason please help
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...