|
-
Dec 17th, 2000, 09:58 PM
#1
Thread Starter
New Member
im new to the winsock control...
i have created a server, and a client which successfully connect, and send and receive data. i want to be able to send one string of data to the server which the server can split up and use those separate strings to execute different commands.
e.g.
i want to send a (one single) string to the server which tels it to display a message box. when the string arives the server splits the string int the folloing variabls
strCMD = "1"
'the command to execute in this case a message box.
strPar1 = "Error!"
'the first parameter for the message box in this case the message box title.
strPar2 = "This is a message from the client!"
'the second Parameter for the message box, in this case, the message to be displayed.
strPar3 = "4096"
' the type of message box to be displayed, in this case system modal.
i have developed ways of acheiving this but they are unreliable and constantly cause errors. if i could send a string array, that would be perfect, but i cannot work out how to do that.
please tell me what to do!!!
-
Dec 18th, 2000, 05:13 AM
#2
You can make use of the Split function.
The client should send a string like this:
"1|Error!|This is a message from the client!|4096"
By using something similar to the following:
Code:
Dim Msg As String
Dim Cmds() As String
Winsock1.GetData Msg
Cmds() = Split(Msg, "|")
The array Cmds() will contain in element 0 "1", element 1 "Error!" and so on. This method works rather well, as long as the string size isn't larger than Winsock's buffer size. If you like, you can post the code you are already using and have that fixed up instead.
Sunny
-
Dec 18th, 2000, 05:45 AM
#3
Thread Starter
New Member
Thank you sunny!
Thank you sunny youve saved my life.
i originally tried something like that, i even used the "|" to separate them. but couldn't reliably separate it at the other end.
this will help me big time
thanx
-
Dec 20th, 2000, 07:29 PM
#4
New Member
How can I programatically find out how many elements there are in this array?
This example has been very helpful to me but I cannot figure out how to determine how many elements there are in Cmds().
Any Suggestions?
Code:
Dim Msg As String
Dim Cmds() As String
Winsock1.GetData Msg
Cmds() = Split(Msg, "|")
-
Dec 20th, 2000, 07:37 PM
#5
You can make use of LBound and UBound
They return the upper and lower limits of an array:
Code:
Dim Str(3) As String
MsgBox UBound(Str)
You will get 3
Sunny
-
Dec 20th, 2000, 07:59 PM
#6
New Member
thanks
Thanks sunny, I guess I've shown how green I am when it comes to VB. Here is a code sample of what I'm trying to do:
Example:
Code:
Private Sub DoStuff()
Dim MyArray() As String
Dim MyString As String
Dim NumberOfElements As Integer
Dim X As Integer
'This could be any FQDN so it is not safe to
'assume a specific number of elements
MyString = "myhost.mysubdomain.mydomain.myrootdomain"
MyArray() = Split( MyString, "." )
NumberOfElements = 'This is what Im trying to find out
For X = 0 To NumerOfElements
DoMoreStuff
Next X
End Sub
-
Dec 20th, 2000, 08:04 PM
#7
You could leave out NumberOfElements all together.
Code:
Private Sub DoStuff()
Dim MyArray() As String
Dim MyString As String
Dim X As Integer
'This could be any FQDN so it is not safe to
'assume a specific number of elements
MyString = "myhost.mysubdomain.mydomain.myrootdomain"
MyArray() = Split( MyString, "." )
For X = 0 To UBound(MyArray)
DoMoreStuff
Next X
End Sub
Sunny
-
Dec 20th, 2000, 08:20 PM
#8
New Member
Yes, that is exactly what I ended up doing:
Code:
Private Sub btnSend_Click()
Dim bArr() As Byte
Dim cArr() As String
Dim X As Integer
ReDim bArr(1 To Len(Header)) As Byte
CopyMemory bArr(1), Header, Len(Header)
cArr() = Split(txtClientFQDN.Text, ".")
ReDim Header.ZONE(UBound(cArr) + 1)
For X = 0 To UBound(cArr)
Header.ZONE(X).ZoneLength = Len(cArr(X))
Header.ZONE(X).ZoneText = cArr(X)
Next X
tcpClient.SendData bArr
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|