Solved

Multi-instances of WINSOCK Control Allowed?

Posted on 1998-12-23
7
389 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

696 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