Solved

Multi-instances of WINSOCK Control Allowed?

Posted on 1998-12-23
7
379 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

21 Experts available now in Live!

Get 1:1 Help Now