-
Oct 15th, 2009, 06:05 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Winsock Multithread : Connect, DataArrival
Hi guys, i've been searching the forum for some info but i did not find what i needed...
What i need to do is :
- send 4 different strings to 4 different ip's (hosts)
- read the data recieved from all the 4 hosts i've sent the data before
So far i have done this :
CONNECT BUTTON :
Hosts(0) = "192.168.1.1"
Hosts(0) = "192.168.1.2"
Hosts(0) = "192.168.1.3
For i = 0 To 2
Winsock1(i).Close
Winsock1(i).Connect Hosts(i), 80
DataToSend(i)= Hosts(i)
next i
WINSOCK CONNECT :
For i = 0 To 2
If Winsock1(i).State = 7 Then Winsock1(i).SendData LOGIN_DATA_SEND(i)
Next i
this code kinda works, winsock connects but sending the first packet in a bad way making multiple lines in DataTosend...but that s not the main problem
Now the problem i have is how to get the DATA ARRIVAL in the approriate arrays.
Like this :
for i=0 to 2
DataRetrieved(i) =
next i
Cheers
Thanks for helping me out.
-
Oct 15th, 2009, 02:18 PM
#2
Re: Winsock Multithread : Connect, DataArrival
You don't have to loop. When you add a Winsock array to your form, then you can simply use the Winsock events and the Index of each connection.
Something like this.
vb Code:
Option Explicit
Private DataToSend(2) As String
Private DataRetrieved(2) As String
Private Hosts(2) As String
Private Sub Command1_Click()
Dim i As Integer
Hosts(0) = "192.168.1.1"
Hosts(1) = "192.168.1.2"
Hosts(2) = "192.168.1.3"
For i = 0 To 2
Winsock1(i).Close
Winsock1(i).Connect Hosts(i), 80
DataToSend(i) = Hosts(i)
Next i
End Sub
Private Sub Form_Load()
'Load two more sockets
Load Winsock1(1)
Load Winsock1(2)
End Sub
Private Sub Winsock1_Connect(Index As Integer)
Winsock1(Index).SendData DataToSend(Index)
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strReturn As String
Winsock1(Index).GetData strReturn, vbString 'receive the data
DataRetrieved(Index) = strReturn
'DataRetrieved(Index) now contains the received data
'Note: if the data is more than a few kB, then you'll need to buffer it
End Sub
-
Oct 15th, 2009, 02:46 PM
#3
Thread Starter
Hyperactive Member
Re: Winsock Multithread : Connect, DataArrival
Thanks man for replying...i was thinking how to do this...
let me try this ... then ill get back to tell how i did
Cheers
Thanks for helping me out.
-
Nov 3rd, 2009, 09:00 AM
#4
Thread Starter
Hyperactive Member
Re: Winsock Multithread : Connect, DataArrival
everything works fine so far...
the only problem i get is on DATA ARRIVAL...i get subscript out of range for this
Code:
DataRetrieved(Index) = strReturn
Thanks for helping me out.
-
Nov 3rd, 2009, 11:46 AM
#5
Re: Winsock Multithread : Connect, DataArrival
How is DataRetrieved declared?
With "Private DataRetrieved(2) As String" you can only use 3 connections. If you want to use more connections, then increase the number in the declaration.
-
Nov 3rd, 2009, 02:20 PM
#6
Thread Starter
Hyperactive Member
Re: Winsock Multithread : Connect, DataArrival
yeah...i got to tthat later one hehehe
btw it seems that sometimes i dont get the entire string back from data arrival even though i put
text1.text = text1.text & strReturn
Thanks for helping me out.
-
Nov 19th, 2009, 07:12 PM
#7
Thread Starter
Hyperactive Member
Re: Winsock Multithread : Connect, DataArrival
it all worked well as u said man
thanks and .. rating
Thanks for helping me out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|