Solved

Multi-instances of WINSOCK Control Allowed?

Posted on 1998-12-23
7
381 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

930 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now