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

Sending a string to a label (Server > Client)


TorenRenne
 Share

Recommended Posts

Asked in the shoutbox was how the packet system works. Its too much hassle doing it in the shoutbox so heres a quick demo:

ModEnumerations (Client & Server)

Under ServerPackets at the bottom add:

```

STest
```
ModServerTCP (Server)

Paste at the bottom (Clone of SayMsg from the client)

```

Public Sub TestMsg()
Dim buffer As clsBuffer

Set buffer = New clsBuffer
buffer.WriteLong STest
buffer.WriteString "I Liek chocolate milk"
SendDataToAll buffer.ToArray()
Set buffer = Nothing

End Sub
```
When you call this sub it will send a string to the client With the identifer of "STest"

ModHandleData (Client)

In Initmessages() you need to tell the program where to process "STest", add:

```

HandleDataSub(STest) = GetAddress(AddressOf HandleTestMsg)
```
Then at the bottom of ModHandleData (Client)

```

Private Sub HandleTestMsg(ByVal Index As Long, ByRef data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
Dim buffer As clsBuffer
Dim Msg As String

Set buffer = New clsBuffer
buffer.WriteBytes data()
Msg = buffer.ReadString
msgbox msg

End Sub
```
Job done. Not 100% accurate, but close enough to work.

Outcome of this, should be a Msgbox which says "I Liek Chocolate Milk" on all connected clients.

![](http://3.bp.blogspot.com/-dLxHcIqQ1_g/TyHiC2AcMRI/AAAAAAAAAAU/gmKSmCESN-s/s220/I%2BLIEK%2BCHOCOLATE%2BMILK.jpg)
Link to comment
Share on other sites

I do have SAnnouncements under the ModEunumerators ServerPackets list (on both Client and Server)

At the bottom of Server's modPlayer I have:

```

Public Sub sendAnnouncements(ByVal text As String)
Dim buffer As clsBuffer

Set buffer = New clsBuffer
buffer.WriteLong SAnnouncements
buffer.WriteString frmServer.txtAnnouncements.text
SendDataToAll buffer.ToArray()
Set buffer = Nothing
End Sub

```
On frmServer I have a new tab for announcements, with txtAnnouncements and cmdSendAnnouncements.  When I went to compile I would get the "Argument not Optional" error, highlighting "Call sendAnnouncements" until I changed it to what I have below:

```

Public Sub cmdSendAnnouncement_Click()

Call sendAnnouncements(frmServer.txtAnnouncements.text)

End Sub

```
Now it works perfectly.  But I agree that it should not require that argument.
Link to comment
Share on other sites

Ok I see your issue, your sub is expecting a "String" to be passed in. The reason to do this is to obviously use the string somewhere in the sub. In this situation your passing in the string, but then not using it. Your instead hard coding the other bit.

You want to either:

Change the sendannouncements sub:

```
Public Sub sendAnnouncements(ByVal content As String)
Dim buffer As clsBuffer

Set buffer = New clsBuffer
buffer.WriteLong SAnnouncements
buffer.WriteString content
SendDataToAll buffer.ToArray()
Set buffer = Nothing
End Sub
```
That means you need to pass in a string. (Like you have done)

As long as the button is on the frmServer you can use:

**sendAnnouncements(txtAnnouncements.text)**

Alternatively:

```
Public Sub sendAnnouncements()
Dim buffer As clsBuffer

Set buffer = New clsBuffer
buffer.WriteLong SAnnouncements
buffer.WriteString frmServer.txtAnnouncements.text
SendDataToAll buffer.ToArray()
Set buffer = Nothing
End Sub
```
Which is hardcoded to send whatever is in that textbox.

and then you would call it with:

**sendAnnouncements**
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...