Notsu Posted January 17, 2013 Author Share Posted January 17, 2013 CLIENT:```Sub SendSomething(ByVal LongValue As Long, ByVal StringValue As String)Dim Buffer As clsBufferSet Buffer = New clsBufferBuffer.WriteLong CGuildCommandBuffer.WriteLong LongValueIf StringValue <> vbNullString Then Buffer.WriteString StringValueEnd IfSendData Buffer.ToArray()Set Buffer = NothingEnd Sub```SERVER:```Sub HandleSomething(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim buffer As clsBufferDim LongValue As Long, StringValue As StringSet buffer = New clsBufferbuffer.WriteBytes Data()LongValue = buffer.ReadLongStringValue = buffer.ReadStringSet buffer = NothingEnd Sub```Is it worth? Is it optimal and done in proper way? I'm saying about lines where is check: if StringValue is not empty then send it.But the server will try to read string if it's not sent in client code.I hope you'll understand. ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png)Thanks for reply. Link to comment Share on other sites More sharing options...
Stein Posted January 17, 2013 Share Posted January 17, 2013 And how are you going to handle this on the receiving end, just assume everything is sent or guess and hope it doesn't crash? Link to comment Share on other sites More sharing options...
Notsu Posted January 17, 2013 Author Share Posted January 17, 2013 That's why I'm asking, I tested it before post and it works without crash. Link to comment Share on other sites More sharing options...
JohnPony Posted January 17, 2013 Share Posted January 17, 2013 That's because you only tested it when you're sending a string.Test it without a string and it will crash, because you're trying to read beyond the byte array's max capacity. Link to comment Share on other sites More sharing options...
Notsu Posted January 18, 2013 Author Share Posted January 18, 2013 No, I tested it with and without stringvalue.(I entered vbNullString as StringValue in that case)But if it should crash I'll delete that check. 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