Results 1 to 13 of 13

Thread: Send listbox content via winsock ???

  1. #1

    Thread Starter
    Addicted Member Tha Joey Madnez's Avatar
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    179

    Send listbox content via winsock ???

    Hi,

    How can i send the content of list1 with winsock to
    list2 ?


    thx !
    100% Done with the Software forLuidia

    Click here to goto the Luidia website

    -=[Visual Basic][Addicted]=-

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Send listbox content via winsock ???

    Quote Originally Posted by Tha Joey Madnez
    Hi,

    How can i send the content of list1 with winsock to
    list2 ?


    thx !
    are these seperate apps or are the listboxes on the same form?

    Pino

  3. #3

    Thread Starter
    Addicted Member Tha Joey Madnez's Avatar
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    179

    Re: Send listbox content via winsock ???

    A client and server
    100% Done with the Software forLuidia

    Click here to goto the Luidia website

    -=[Visual Basic][Addicted]=-

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Send listbox content via winsock ???

    You could add the list items to one string, send and then split and add to the other listbox. But, I guess you would have to use weird characters to avoid messing up the splitting of the recieved string.


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Addicted Member Tha Joey Madnez's Avatar
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    179

    Re: Send listbox content via winsock ???

    Got any code ?
    100% Done with the Software forLuidia

    Click here to goto the Luidia website

    -=[Visual Basic][Addicted]=-

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Send listbox content via winsock ???

    Kinda like this. Haven't tested it but it's the general idea :

    VB Code:
    1. 'Send code
    2.     Dim i As Integer
    3.     Dim strSend As String
    4.     Dim sDelimiter As String
    5.    
    6.     sDelimiter = "+++"
    7.    
    8.     For i = 0 To List1.ListCount - 1
    9.         strSend = strSend & List1.List(i) & sDelimiter
    10.     Next
    11.    
    12.     strSend = Left(strSend, Len(strSend) - Len(sDelimiter))
    13.     'After here, you send

    And

    VB Code:
    1. 'Recieve code
    2.     Dim i As Integer
    3.     Dim strData As String
    4.     Dim sDelimiter As String
    5.     Dim Ar() As String
    6.    
    7.     sDelimiter = "+++"
    8.    
    9.     Ar = Split(strData, sDelimiter)
    10.    
    11.     For i = 0 To UBound(Ar)
    12.         List2.AddItem Ar(i)
    13.     Next

    The only problem is that if an item in the listbox has +++ in it, the splitting won't work right


    Has someone helped you? Then you can Rate their helpful post.

  7. #7
    Member
    Join Date
    Mar 2004
    Posts
    46

    Re: Send listbox content via winsock ???

    This is the idea but it doesn't really work as the data is send to fast just appears as one string, ways around it though.

    server,

    VB Code:
    1. Option Explicit
    2.  
    3.  
    4. Private Sub Form_Load()
    5.  
    6.     With Winsock1
    7.         .LocalPort = 9999
    8.         .Listen
    9.     End With
    10.     Form1.Show
    11.  
    12. End Sub
    13.  
    14. Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    15.  
    16.     Winsock1.Close
    17.     Winsock1.Accept requestID
    18.  
    19. End Sub
    20.  
    21. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    22.  
    23. Dim dat As String
    24.  
    25.     Winsock1.GetData dat
    26.     List1.AddItem dat
    27.  
    28. End Sub

    client,

    VB Code:
    1. Option Explicit
    2. Private i  As Long
    3.  
    4.  
    5. Private Sub Command1_Click()
    6.  
    7.     For i = 0 To List1.ListCount - 1
    8.         Winsock1.SendData List1.List(i)
    9.        
    10.         DoEvents
    11.         DoEvents
    12.     Next i
    13.  
    14. End Sub
    15.  
    16.  
    17.  
    18. Private Sub Form_Load()
    19.  
    20.     Winsock1.Connect "localhost", 9999
    21.     For i = 0 To 10
    22.         List1.AddItem "test" & i
    23.     Next i
    24.  
    25. End Sub

  8. #8

    Thread Starter
    Addicted Member Tha Joey Madnez's Avatar
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    179

    Re: Send listbox content via winsock ???

    ThX !
    100% Done with the Software forLuidia

    Click here to goto the Luidia website

    -=[Visual Basic][Addicted]=-

  9. #9
    Member
    Join Date
    Mar 2004
    Posts
    46

    Re: Send listbox content via winsock ???

    Here's a way of creating a delay, bit long winded though,

    server,

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  
    5.     With Winsock1
    6.         .LocalPort = 9999
    7.         .Listen
    8.     End With
    9.     Form1.Show
    10.  
    11. End Sub
    12.  
    13. Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    14.  
    15.     Winsock1.Close
    16.     Winsock1.Accept requestID
    17.  
    18. End Sub
    19.  
    20. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    21.  
    22. Dim dat As String
    23.  
    24.     Winsock1.GetData dat
    25.     List1.AddItem dat
    26.     Winsock1.SendData "NEXT"
    27.  
    28. End Sub

    client,

    VB Code:
    1. Option Explicit
    2. Private i  As Long
    3. Private j  As Long
    4.  
    5. Private Sub Command1_Click()
    6.  
    7.     If j > List1.ListCount Then
    8.         Winsock1.Close
    9.     End If
    10.     Winsock1.SendData List1.List(j)
    11.     j = j + 1
    12.  
    13. End Sub
    14.  
    15. Private Sub Form_Load()
    16.  
    17.     Winsock1.Connect "localhost", 9999
    18.     For i = 0 To 10
    19.         List1.AddItem "test" & i
    20.     Next i
    21.  
    22. End Sub
    23.  
    24. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    25.  
    26. Dim dat As String
    27.  
    28.     Winsock1.GetData dat
    29.     If dat = "NEXT" Then
    30.         Command1_Click
    31.     End If
    32.  
    33. End Sub

  10. #10
    Member
    Join Date
    Mar 2004
    Posts
    46

    Re: Send listbox content via winsock ???

    You'll find though that when your sending data over the internet there will be a delay anyway due to the distance, well depening on the conection speeds, so my first method would probably work fine in that case. Second method is fullproof though.

  11. #11
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Send listbox content via winsock ???

    why not use packet delimeters? theres a link in my sig



    Pino

  12. #12
    Member
    Join Date
    Feb 2005
    Location
    Usa Nyc
    Posts
    45

    Re: Send listbox content via winsock ???

    If your app is going to do more then send packets containing the list content i suggest when you send your list content you add a header "LIST" or something like that in the beginning of the packet so you can check and process each packet the way it needs. Use chr(13) as a delimeter.
    Kiss, Aerosmith, Black Sabbath, Nazareth, Judas Priest, Status Quo, Cinderella, Scorpions, Tool, SteppenWolf.

  13. #13
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Send listbox content via winsock ???

    Quote Originally Posted by Pino
    why not use packet delimeters? theres a link in my sig



    Pino
    This is what my example did, I just couldn't remember what the method is called

    patcher, you could also create a delay based on the SendComplete event of the winsock that is sending


    Has someone helped you? Then you can Rate their helpful post.

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