Results 1 to 5 of 5

Thread: send and receive entire array

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    how can i send an entire array through winsock and receive it on the other end, not knowing how big the array is on the other end??

    is there a way like:
    dim myArray(1 to 5) as String

    winsock1.sendData myArray(1 to 5)

    is that allowed?

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    I haven't played with winsock but that is no way to read an array. If you don't know the size of an array you can use

    ReDim Preserve

    Ie.
    Randomize
    Dim myArr()
    For i = 1 to len(something)
    Redim Preserve myArr(i)
    myArr(i) = i & (Rnd*10)
    next i

    This will load the array from 0 to len(something)
    without knowing what that len(something might be at start)

    to load the array into a list box for example
    lbound is the lowest of the array and ubound is the highest
    0 to whatever

    For i = lBound(myArr) to UBound(myarr)
    list1.additem myarr(i)
    next i
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    You need a prefix/suffix message

    Put your example into more "real world" terms and you will figure out what needs to be done.

    Imagine you need to talk to me. You have my phone number which you dial. I pick up the phone and acknowledge that I am here. This is similar so far to the work you have done to establish the winsock session.

    Now you start talking to me and I listen, recording everything you say perhaps. This is equivalent to you sending an array to the remote end.

    Now what? Do you hang up? Do you sit there waiting in case you have more to say? Do I sit there waiting or do I eventually figure out that you've stopped? But what if you haven't stopped, and only had a pause?

    The answer you arrive at should be similar to my answer: You need to establish a simple message system between your remote and local ends so that each end knows exactly what is happening.

    In my real world example, you would say "I'm going to talk". I might say "OK", then you would talk, while I record, and finally you would say "I am finished talking" and I would say "OK". To be safer, I might even say to you "Did you send 2000 words?" to which you would reply "Yes" or "NO' - i.e. we are checking that what was sent is what was recieved.

    There in a nutshell you have what I think you need to do.

    If you need help coding something like this, post a message.

    Regards



    Paul Lewis

  4. #4
    Guest
    Combining what HeSaidJoe suggested with Winsock, you could use the following code:

    [code]
    Dim MyArr() As String
    Dim i As Integer

    For i = 0 To UBound(MyArr)
    If i = UBound(MyArr) Then
    Winsock1.SendData MyArr & "END" 'last one
    Else
    Winsock1.SendData MyArr & "|"
    End If
    Next i

    The reason the "|" is that when you use Winsock in this manner with the SendData's stuck together, Winsock will send it all as one string (if it is not too big), so on the receiving end, you can tell what was one member of the array by searching the received string for "|"s. And when you see a "END" you will know it is the last one. Note this is only good if the string isn't too long.


    Sunny

  5. #5
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Why do my posts do that??

    I am sure I am doing something weird so please tell me. I want word wrapping but it doesn't seem to do it?

    Cheers
    Paul Lewis

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