Results 1 to 5 of 5

Thread: Downloading with Winsock array

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Downloading with Winsock array

    Hi, I've used Winsock arrays many times before, but I'm not really sure how to do this. It's a bit complicated, but I'll try to explain it the best I can.

    I have several items in a Listview. To each Listview item belongs a Collection with strings (between 1 and 300). I need to send each string in the first Collection to the server and the server automatically sends data back. This needs to be done with multiple connections.

    After all the strings from the first collection have been sent to the server and all the data the server has sent back is received, then the item in the Listview has to be removed.

    Then all the strings from the second collection have to be send to the server. After all the strings from the second collection have been sent to the server and all the data the server has sent back is received, then that item in the Listview has to be removed... etc, etc, until the end of the Listview.

    Below is some pseudo code. I'm specifically having problems with the "DownloadNextPart" sub.


    vb Code:
    1. Option Explicit
    2.  
    3. Private col(1 To 5) As Collection
    4. Private strData(1 To 4) As String
    5. Private BufferData(1 To 4) As String
    6.  
    7. Private Sub Form_Load()
    8.     Dim i As Integer, x As Integer
    9.    
    10.     For i = 1 To 5
    11.         lvwItems.ListItems.Add , , "Item in Listview: " & i 'several items in the listview
    12.    
    13.         'add strings to the Collections (just an example)
    14.         Set col(i) = New Collection
    15.         For x = 1 To 50
    16.             col(i).Add "string to send to the server"
    17.         Next x
    18.        
    19.     Next i
    20.    
    21. End Sub
    22.  
    23. Private Sub Command1_Click()
    24.     Dim i As Integer
    25.    
    26.     For i = 1 To 4 '4 connections to the server
    27.         Sockets(i).Close
    28.         Sockets(i).Connect "someserver.com", 80
    29.     Next i
    30.  
    31. End Sub
    32.  
    33. Private Sub Sockets_Connect(Index As Integer)
    34.  
    35.     Call DownloadNextPart(Index) 'start downloading when connected to the server
    36.  
    37. End Sub
    38.  
    39. 'I'm not sure how to make this work properly
    40. '????
    41. Private Sub DownloadNextPart(Index As Integer)
    42. Dim i As Long
    43.  
    44.     With lvwItems
    45.         For i = 1 To .ListItems.Count 'loop through listview items
    46.  
    47.             If Sockets(Index).State = sckConnected Then
    48.                
    49.                 'send next string in collection
    50.                 'if there are no more strings to be sent from a collection then
    51.                 'start sending strings from the next collection ????
    52.                 Sockets(Index).SendData col(.ListItems(i).Tag).Item(???????) & vbCrLf
    53.                
    54.                 Exit Sub
    55.             End If
    56.    
    57.         Next i
    58.     End With
    59.    
    60. End Sub
    61.  
    62. Private Sub Sockets_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    63.  
    64.     Sockets(Index).GetData strData(Index), vbString 'get data
    65.  
    66.     BufferData(Index) = BufferData(Index) & strData(Index) 'buffer data
    67.    
    68.    
    69.     If InStr(1, BufferData(Index), "...") Then ' all data has been received
    70.         'do something with it
    71.  
    72.         BufferData(Index) = vbNullString 'clear buffer
    73.     End If
    74.    
    75.     'if this is the returned data from the last string
    76.     'in the collection, then remove Listview item ?????
    77.  
    78.     Call DownloadNextPart(Index) 'download next part
    79. End Sub
    Last edited by Chris001; Jul 25th, 2008 at 01:57 PM.

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