Results 1 to 12 of 12

Thread: winsock - sendData & dataArrival - part 2

  1. #1

    Thread Starter
    Fanatic Member drivenbywhat's Avatar
    Join Date
    Jan 2007
    Location
    VA - USA
    Posts
    866

    winsock - sendData & dataArrival - part 2

    I started this thread a while ago in reference to why data sent arrived bunched up. In conclusion, it was because that was the way it was meant to be sent and there were two possible solutions to this. Add a special character at the end of the data and then split the data by that special character when it arrived or use a timer.

    I use a combination of these two. I wait 3 seconds before sending data again and use the split to get the data seperated. However, I use the sendData 6 times, which means it takes 18 seconds to send the data. I'm now needing to sendData 10 times. Which means it will make my program take 30 seconds to send its data. That's too long. So I'm thinking of just using the split method. However, is it possible in the following scenario:

    So here is my question. I know how to send data with special characters & receive the data and split it at the special characters. I am able to do this because I know how many items are being sent. However, what about when the items you are sending are in a listboxes and the listcount is different everytime? Unless I'm over-thinking, using the special character and splitting is out of the question isn't it? I would have to send the data from each listbox as a seperate sendData using timers to make sure data isn't bunched up. I wouldn't be able to "bunch" all the data together and and try to split it at the receiving end because since the listcount is not the same as before. I can't determine which data came from which listbox.

    Anyone get what I'm saying?
    [vb5 & starting to move to vb2008] I appreciate the help I get from everyone. Thank you.

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: winsock - sendData & dataArrival - part 2

    No need for any timers or pausing. Just separate each SendData "packet" with a special character at the end and split it up when it arrives.

    When sending list data, I usually just separate each list item by a new line (vbCrLf) since chances are, you won't have any new line characters in a list item.

    So you would have 3 separaters.

    1 is the one you use at the end of your SendData packet.
    2nd is the one you use to separate each list item (vbCrLf)
    And 3rd is what you use to separate the other info in the packet.

    ie:

    vb Code:
    1. Dim intLoop As Integer, strPacket As String
    2.  
    3. strPacket = "LIST" & Chr$(2) & "Another part" & Chr$(2) & "Another part" & Chr$(2)
    4.  
    5. For intLoop = 0 To List1.ListCount - 1
    6.     strPacket = strPacket & List1.List(intLoop) & vbCrLf
    7. Next intLoop
    8.  
    9. 'Remove last new line if it is there.
    10. If Right$(strPacket, 2) = vbCrLf Then strPacket = Mid$(strPacket, 1, Len(strPacket)-2)
    11.  
    12. strPacket = strPacket & Chr$(4)
    13.  
    14. Winsock.SendData strPacket

    So then your data would look like this:

    LIST[2]Another part[2]Another part[2]Item1
    Item2
    Item3
    Item4


    Where [2] (Chr$(2)) separates each "parameter" or other piece of information in the packet. And [4] (Chr$(4)) separates each actual packet in case they arrive together.

    Splitting by [2] (which is Chr$(2)) would give you:

    vb Code:
    1. strInfo() = Split(Data, Chr$(2))
    2. 'strInfo(0) = LIST
    3. 'strInfo(1) = Another part
    4. 'strInfo(2) = Another part
    5. 'strInfo(3) = Item1
    6. Item2
    7. Item3
    8. Item4

    Then splitting strInfo(3) by vbCrLf would give you the list items.

    vb Code:
    1. strList() = Split(strInfo(3), vbCrLf)

    Then you can loop through the array and add each item to the list.

    vb Code:
    1. Dim intLoop As Integer
    2.  
    3. For intLoop = 0 To UBound(strList)
    4.     List1.AddItem strList(intLoop)
    5. Next intLoop
    6.  
    7. Erase strInfo
    8. Erase strList

  3. #3

    Thread Starter
    Fanatic Member drivenbywhat's Avatar
    Join Date
    Jan 2007
    Location
    VA - USA
    Posts
    866

    Re: winsock - sendData & dataArrival - part 2

    Thanks for the reply DigiRev. I had a feeling you would be monitoring this forum.

    Now please be patient with me because I'm slow when it comes to new things. Also, I'm not 100% sure if this would do what I need. I have more than 1 listbox. Not just one. I can do many listboxes with no problem. The problem is trying to send the data from all the listboxes in 1 shot & splitting it at the receiving end in 1 shot. Well, I can send everything in one shot, just don't know how to split it on the other side to the appropriate listboxes. I don't know if your code does this and I'm just not understanding.

    Here is part of the code I use to send the items in the listboxes. Don't pay too much attention to the select case. I just use it for my timer that holds a static integer variable to know what is arriving. I use the @ for the special split character:

    vb Code:
    1. Select Case x
    2.     Case 1  'deck cards for u1
    3.         If lstDeckU1.ListCount > 0 Then
    4.             For y = 0 To lstDeckU1.ListCount - 1
    5.                 deckCardsU1 = deckCardsU1 & lstDeckU1.List(y) & "@"
    6.             Next y
    7.         Else
    8.             deckCardsU1 = "e@"
    9.         End If
    10.        
    11.         Winsock.SendData deckCardsU1
    12.        
    13.     Case 2  'deck cards for u2
    14.         If lstDeckU2.ListCount > 0 Then
    15.             For y = 0 To lstDeckU2.ListCount - 1
    16.                 deckCardsU2 = deckCardsU2 & lstDeckU2.List(y) & "@"
    17.             Next y
    18.         Else
    19.             deckCardsU2 = "e@"
    20.         End If
    21.    
    22.     Winsock.SendData deckCardsU2

    Here is part of the code I use to receive & split the items in the listboxes:

    vb Code:
    1. Select Case x
    2.             Case 1  'u1 deck
    3.                 If unkMsg <> "e@" Then
    4.                     theUpdates = Split(unkMsg, "@")
    5.                     lstDeckU1.Clear
    6.                     For y = 1 To UBound(theUpdates)
    7.                         lstDeckU1.AddItem theUpdates(y)
    8.                     Next y
    9.                 End If
    10.                
    11.             Case 2  'u2 deck
    12.                 If unkMsg <> "e@" Then
    13.                     theUpdates = Split(unkMsg, "@")
    14.                     lstDeckU2.Clear
    15.                     For y = 1 To UBound(theUpdates)
    16.                         lstDeckU2.AddItem theUpdates(y)
    17.                     Next y
    18.                 End If

    Before I gave up and resorted to the above code, this is what I had done for the sending part:

    vb Code:
    1. Case 1  'deck cards
    2.         If lstDeckU1.ListCount > 0 Then
    3.             For y = 0 To lstDeckU1.ListCount - 1
    4.                 deckCards = deckCards & lstDeckU1.List(y) & "@"
    5.             Next y
    6.             deckCards = deckCards & "done@"
    7.         Else
    8.             deckCards = "e@"
    9.         End
    10.        
    11.         If lstDeckU2.ListCount > 0 Then
    12.             For y = 0 To lstDeckU2.ListCount - 1
    13.                 deckCards = deckCards & lstDeckU2.List(y) & "@"
    14.             Next y
    15.             deckCards = deckCards & "done@"
    16.         Else
    17.             deckCards = deckCards & "e@"
    18.         End If

    At the receiving part:

    vb Code:
    1. Case 1  'decks
    2.  
    3.           theUpdates = Split(unkMsg, "@")
    4.                 If theUpdates(1) <> "e" Then                    
    5.                     lstDeckU1.Clear
    6.                     For y = 1 To UBound(theUpdates)
    7.                         If theUpdates(y) <> "done" then
    8.                                 lstDeckU1.AddItem theUpdates(y)
    9.                         Else
    10.                                 Exit For
    11.                         End If
    12.                     Next y
    13.                 End If
    14.                
    15.                 z = y + 1
    16.                 If theUpdates(z) <> "e"
    17.                     lstDeckU2.Clear
    18.                    
    19.                     For x = z To UBound(theUpdates)
    20.                        If theUpdates(z) <> "done" then
    21.                              lstDeckU2.AddItem theUpdates(z)
    22.                        End If
    23.                     Next x
    24.                 End If

    I think I'm pretty close with the code I wrote but I couldn't finish it. The if/thens & for/nexts got confusing. This code "should" work perfectly for my needs if the listcount for each list had at least 1 item. When the first or both lists are emtpy, which have the string of "e", then I don't know where in the code to insert more code to jump "out" or what code to put period.

    Keep in mind I have 6 listboxes. If I'm having trouble with just 2, imagine how much trouble I will have with 6. So I wouldn't mind if I could send the listboxes by 2.
    [vb5 & starting to move to vb2008] I appreciate the help I get from everyone. Thank you.

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: winsock - sendData & dataArrival - part 2

    Your problem is that the receiver doesn't know the number of items that belong to a listbox (or whatever). However since your sender knows that number, why don't you send the number of items before you start to send the items. That way the receiver could start the correct for/next loop using just this number!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: winsock - sendData & dataArrival - part 2

    Damn I remember reading your reply and starting an example project but I must have got sidetracked with my projects.

    I'll write an example for you today if I can, if not, then tomorrow. Trying to finish up this chat program.

  6. #6
    Junior Member
    Join Date
    Aug 2007
    Posts
    17

    Re: winsock - sendData & dataArrival - part 2

    I only send data in "Swan plant web" , But I Can't To make Chat online program . T_T . Can You Send Me Simple source Code about The Winsock to Make chat online .

  7. #7

    Thread Starter
    Fanatic Member drivenbywhat's Avatar
    Join Date
    Jan 2007
    Location
    VA - USA
    Posts
    866

    Re: winsock - sendData & dataArrival - part 2

    Quote Originally Posted by GiongTo
    I only send data in "Swan plant web" , But I Can't To make Chat online program . T_T . Can You Send Me Simple source Code about The Winsock to Make chat online .
    Your question doesn't have anything to do with mine. You start a new thread if your reply isn't in reference to what is already started in the thread. However, I see that you're new. Here is a link:

    http://www.vbforums.com/showthread.php?t=297308
    [vb5 & starting to move to vb2008] I appreciate the help I get from everyone. Thank you.

  8. #8
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: winsock - sendData & dataArrival - part 2

    Sorry, been real busy and I forgot again. But here's an example.
    Attached Files Attached Files

  9. #9
    Junior Member
    Join Date
    Aug 2007
    Posts
    17

    Re: winsock - sendData & dataArrival - part 2

    HIHI many Thanks

  10. #10

    Thread Starter
    Fanatic Member drivenbywhat's Avatar
    Join Date
    Jan 2007
    Location
    VA - USA
    Posts
    866

    Re: winsock - sendData & dataArrival - part 2

    Ahhhh! vb5 and its lack of vb6 built in functions is annoying. I don't have INSTREV function. However, I'm trying to study your code to see how you went about it. I see you used INSTR to find the "/" during data arrival through calling a function.

    I know what INSTR does but what does INSTRREV do again? Does it do the same as INSTR but starts from the right side first?

    Don't worry about forgetting & taking a while. I don't have an immediate need for the code. Plus the code I have is working, just not as fast as I would like.
    [vb5 & starting to move to vb2008] I appreciate the help I get from everyone. Thank you.

  11. #11
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: winsock - sendData & dataArrival - part 2

    Quote Originally Posted by drivenbywhat
    Ahhhh! vb5 and its lack of vb6 built in functions is annoying. I don't have INSTREV function. However, I'm trying to study your code to see how you went about it. I see you used INSTR to find the "/" during data arrival through calling a function.

    I know what INSTR does but what does INSTRREV do again? Does it do the same as INSTR but starts from the right side first?

    Don't worry about forgetting & taking a while. I don't have an immediate need for the code. Plus the code I have is working, just not as fast as I would like.
    Yeah, InStrRev is the opposite of InStr, starts from the end of the string, to find the last occurence of something.

    I don't think VB5 has Split() either.

    I can modify the example to work without these functions. Are these the only 2 that are missing?

  12. #12

    Thread Starter
    Fanatic Member drivenbywhat's Avatar
    Join Date
    Jan 2007
    Location
    VA - USA
    Posts
    866

    Re: winsock - sendData & dataArrival - part 2

    INSTRREV & SPLIT are the ones that I know vb5 doesn't have but I'm sure there a few more that I haven't had to use.
    [vb5 & starting to move to vb2008] I appreciate the help I get from everyone. Thank you.

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