Results 1 to 3 of 3

Thread: Sendin And REcieving List Box info via Winsock...

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    56

    Sendin And REcieving List Box info via Winsock...

    could somebody give me guideance on sending the data contained in 3 listboxes from the server, to client, via winsock...

    I have 3 listboxes on the server App:

    List1.............List2............List3
    string...........string...........(string or integer, yet to decide)

    And exactly the same, but empty on the client side...How can i get this data accross, keeping the data in the correct listboxes, and correct row...

    Thank you for any assistance/links

    Dave

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    I did not test the code, but theoreticly it's something like this

    VB Code:
    1. ' to send the data
    2. Private Sub Form_Load()
    3.     Dim PB As New PropertyBag, K As Long
    4.     Dim DataToSend() As Byte
    5.    
    6.     List1.AddItem "df"
    7.     List1.AddItem "sdff"
    8.     List1.AddItem "rtwf"
    9.     List1.AddItem "ytret"
    10.     List1.AddItem "ertu"
    11.     List1.AddItem "gfhjg"
    12.     List1.AddItem "bvnmbn"
    13.    
    14.     List2.AddItem "qwerqwe"
    15.     List2.AddItem "123413"
    16.     List2.AddItem "fgfsdf"
    17.     List2.AddItem "vbnvtyrt"
    18.     List2.AddItem "drtigeri"
    19.    
    20.     List3.AddItem "uiuoi"
    21.     List3.AddItem "sdfgdsf"
    22.     List3.AddItem "zxcv"
    23.     List3.AddItem "zxcv"
    24.     List3.AddItem "qwr"
    25.     List3.AddItem "tryuty"
    26.     List3.AddItem "cvbcvbvbv"
    27.    
    28.     PB.WriteProperty "LST1_COUNT", List1.ListCount
    29.     For K = 0 To List1.ListCount - 1
    30.         PB.WriteProperty "LST1_" & K, List1.List(K)
    31.     Next K
    32.    
    33.     PB.WriteProperty "LST2_COUNT", List2.ListCount
    34.     For K = 0 To List2.ListCount - 1
    35.         PB.WriteProperty "LST2_" & K, List2.List(K)
    36.     Next K
    37.    
    38.     PB.WriteProperty "LST3_COUNT", List3.ListCount
    39.     For K = 0 To List3.ListCount - 1
    40.         PB.WriteProperty "LST3_" & K, List3.List(K)
    41.     Next K
    42.    
    43.     DataToSend() = PB.Contents
    44.    
    45.     Winsock1.SendData "DATA_LENGTH={" & (UBound(DataToSend) + 1) & "}="
    46.     Winsock1.SendData PB.Contents
    47. End Sub
    48.  
    49. ' when receiving data
    50. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    51.     Static TotalLength As Long, MyData As String
    52.    
    53.     Dim mData As String, DataReceived() As Byte, PB As New PropertyBag, K As Long
    54.     Winsock1.GetData mData
    55.    
    56.     If mData Like "DATA_LENGTH={#*}=" And TotalLength = 0 Then
    57.         TotalLength = Val(Mid(mData, InStr(1, mData, "={") + 3))
    58.         mData = Mid(mData, InStr(1, mData, "}=") + 3)
    59.     End If
    60.    
    61.     MyData = MyData & mData
    62.    
    63.     If Len(MyData) >= TotalLength Then
    64.         DataReceived() = StrConv(MyData, vbUnicode)
    65.         PB.Contents = DataReceived
    66.        
    67.         For K = 0 To Val(PB.ReadProperty("LST1_COUNT"))
    68.             List1.AddItem PB.ReadProperty("LST1_" & K)
    69.         Next K
    70.        
    71.         For K = 0 To Val(PB.ReadProperty("LST2_COUNT"))
    72.             List2.AddItem PB.ReadProperty("LST2_" & K)
    73.         Next K
    74.        
    75.         For K = 0 To Val(PB.ReadProperty("LST3_COUNT"))
    76.             List3.AddItem PB.ReadProperty("LST3_" & K)
    77.         Next K
    78.        
    79.         TotalLength = 0
    80.         MyData = ""
    81.     End If
    82. End Sub

  3. #3
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    I just tested the code I pasted previously, and I had some small mistakes, otherwise it works perfectly...

    VB Code:
    1. ' when receiving data
    2. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    3.     Static TotalLength As Long, MyData As String
    4.    
    5.     Dim mData As String, DataReceived() As Byte, PB As New PropertyBag, K As Long
    6.     Winsock1.GetData mData
    7.    
    8.     If mData Like "DATA_LENGTH={#*}=*" And TotalLength = 0 Then
    9.         TotalLength = Val(Mid(mData, InStr(1, mData, "={") + 2))
    10.         mData = Mid(mData, InStr(1, mData, "}=") + 2)
    11.     End If
    12.    
    13.     MyData = MyData & mData
    14.    
    15.     If Len(MyData) >= TotalLength Then
    16.         DataReceived() = StrConv(MyData, vbFromUnicode)
    17.         PB.Contents = DataReceived
    18.        
    19.         For K = 0 To Val(PB.ReadProperty("LST1_COUNT")) - 1
    20.             List1.AddItem PB.ReadProperty("LST1_" & K)
    21.         Next K
    22.        
    23.         For K = 0 To Val(PB.ReadProperty("LST2_COUNT")) - 1
    24.             List2.AddItem PB.ReadProperty("LST2_" & K)
    25.         Next K
    26.        
    27.         For K = 0 To Val(PB.ReadProperty("LST3_COUNT")) - 1
    28.             List3.AddItem PB.ReadProperty("LST3_" & K)
    29.         Next K
    30.        
    31.         TotalLength = 0
    32.         MyData = ""
    33.     End If
    34. 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
  •  



Click Here to Expand Forum to Full Width