Results 1 to 8 of 8

Thread: send a multi-function command from a client to a server, useing winsock

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Canberra - Australia
    Posts
    8
    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!!!
    *Waco_Jaco*

  2. #2
    Guest
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Canberra - Australia
    Posts
    8

    Smile 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
    *Waco_Jaco*

  4. #4
    New Member
    Join Date
    Dec 2000
    Location
    Cincinnati, OH
    Posts
    4

    Question 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, "|")
    VB6 SP4

  5. #5
    Guest
    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

  6. #6
    New Member
    Join Date
    Dec 2000
    Location
    Cincinnati, OH
    Posts
    4

    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
    VB6 SP4

  7. #7
    Guest

    Smile

    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

  8. #8
    New Member
    Join Date
    Dec 2000
    Location
    Cincinnati, OH
    Posts
    4
    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
    VB6 SP4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width