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?
Printable View
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?
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
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
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
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