TorenRenne Posted July 3, 2013 Author Share Posted July 3, 2013 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 clsBufferSet buffer = New clsBufferbuffer.WriteLong STestbuffer.WriteString "I Liek chocolate milk"SendDataToAll buffer.ToArray()Set buffer = NothingEnd 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 clsBufferDim Msg As StringSet buffer = New clsBufferbuffer.WriteBytes data()Msg = buffer.ReadStringmsgbox msgEnd 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 More sharing options...
tehl33tjim Posted July 3, 2013 Share Posted July 3, 2013 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 clsBufferSet buffer = New clsBufferbuffer.WriteLong SAnnouncementsbuffer.WriteString frmServer.txtAnnouncements.textSendDataToAll buffer.ToArray()Set buffer = NothingEnd 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 More sharing options...
TorenRenne Posted July 3, 2013 Author Share Posted July 3, 2013 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 clsBufferSet buffer = New clsBufferbuffer.WriteLong SAnnouncementsbuffer.WriteString contentSendDataToAll buffer.ToArray()Set buffer = NothingEnd 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 clsBufferSet buffer = New clsBufferbuffer.WriteLong SAnnouncementsbuffer.WriteString frmServer.txtAnnouncements.textSendDataToAll buffer.ToArray()Set buffer = NothingEnd 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now