Solved

Multi-instances of WINSOCK Control Allowed?

Posted on 1998-12-23
7
385 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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.
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 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