Solved

Multi-instances of WINSOCK Control Allowed?

Posted on 1998-12-23
7
384 Views
Last Modified: 2013-11-13
I have created a form which incorporates 10 Winsock controls in a array ie. Winsock(0)..Winsock(10). The odd part is when i try to access more than 1 of these winsocks at the same time it ALWAYS crashes the entire app?  Is it possible to use multi-instances of Winsock?  Here is my code...maybe you can see what is wrong:

BTW i have 10 Winsock controls on this app, 11 Labels, 2 Buttons (to start and stop app), and a ListBox that holds all of the websites to call.


Dim stopNow As Boolean, success As Integer
Private Sub Command1_Click()
    Dim wCount As Byte, SiteToUse As Integer
    stopNow = False
    Do
        Select Case Winsock(wCount).Tag
            Case "0" ' Not Used
                Winsock(wCount).LocalPort = 0
                Winsock(wCount).RemoteHost = List.List(SiteToUse)
                SiteToUse = SiteToUse + 1
                If SiteToUse = List.ListCount Then SiteToUse = 0
                Winsock(wCount).RemotePort = 80
                Winsock(wCount).Tag = "1"
                Winsock(wCount).Connect
            Case "2" ' Connected
                Label(wCount).Caption = "Connected!"
                Winsock(wCount).SendData "GET / HTTP/1.0" & vbCrLf & vbCrLf
            Case "-1" 'Error
                Label(wCount).Caption = "Closing ..."
                Winsock(wCount).Close
                Winsock(wCount).Tag = "-2"
        End Select
               
        Select Case Winsock(wCount).State
            Case sckClosed
                Label(wCount).Caption = "Connection Closed."
                Winsock(wCount).Tag = "0"
            Case sckResolvingHost
                Label(wCount).Caption = "Resolving Host ..."
            Case sckHostResolved
                Label(wCount).Caption = "Host Resolved."
            Case sckConnecting
                Label(wCount).Caption = "Connecting ..." & List.List(SiteToUse - 1)
            Case sckConnected
                Label(wCount).Caption = "Connected to: " & List.List(SiteToUse - 1)
        End Select
        wCount = wCount + 1
        If wCount > 9 Then wCount = 0
        DoEvents
    Loop Until stopNow = True
End Sub

Private Sub Command2_Click()
Dim inc As Byte
For inc = 0 To 9
    Label(inc).Caption = ""
    Winsock(inc).Tag = "0"
    Winsock(inc).Close
Next inc
success = 0
Labels.Caption = ""
stopNow = True
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Call Command2_Click
End Sub

Private Sub Winsock_Connect(index As Integer)
    Label(index).Caption = "Connected."
    Winsock(index).Tag = "2"
End Sub

Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long)
    Static data(10) As String
    Dim str As String
   
    Label(index).Caption = "Data Received."
    Winsock(index).GetData str, vbString
    data(index) = data(index) & str
    If Len(data(index)) >= 500 Or InStr(1, data(index), vbCrLf & vbCrLf) > 0 Or InStr(1, data(index), vbLf & vbCrLf) > 0 Or InStr(1, data(index), vbCrLf & vbLf) > 0 Or InStr(1, data(index), vbLf & vbLf) > 0 Then
        Beep
        Label(index).Caption = "Success."
        success = success + 1
        Labels.Caption = "Success: " & CStr(success)
        Winsock(index).Tag = "-2"
        Winsock(index).Close
        data(index) = ""
    End If
End Sub

Private Sub Winsock_Error(index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    Label(index).Caption = CStr(Number) & ":" & Description
    Winsock(index).Tag = "-2"
    Winsock(index).Close
End Sub

Private Sub Winsock_SendComplete(index As Integer)
    Label(index).Caption = "Send Complete. Waiting ..."
End Sub

Private Sub Winsock_SendProgress(index As Integer, ByVal bytesSent As Long, ByVal bytesRemaining As Long)
    Label(index).Caption = "Sending Data ..."
End Sub
0
Comment
Question by:ljaques
7 Comments
 
LVL 2

Accepted Solution

by:
cedricd earned 30 total points
ID: 1452304
give me your e-mail and i will send you a sample of program using the multi instance of winsock (done by me and some friend for a study work)
cedric.defosse@moodif.com
0
 
LVL 2

Expert Comment

by:cedricd
ID: 1452305
for 50 points ? :-)
0
 
LVL 1

Expert Comment

by:MAVERICK
ID: 1452306
This come up in another problem i was working on...
Would u consider it if I put up the other 20 points... (or I'll give you 50 if you want :) )
tomcat203@geocities.com .....


0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 2

Expert Comment

by:cedricd
ID: 1452307
OK put your question and i'll send you the pgm
0
 
LVL 4

Expert Comment

by:komandur
ID: 2813565
I deposited 3 points to see this answer!! ;(
0
 

Expert Comment

by:MHacker
ID: 2831773
Same here, you should atleast post a URL for the program.
0
 

Expert Comment

by:PolarisN
ID: 3389910

Eh? My points are dwindling, and cedricd appears to be pulling a fast one! What a con :-(
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question