• Welcome to Valhalla Legends Archive.
 

WithEvents & Winsock

Started by Eric, September 01, 2004, 04:14 PM

Previous topic - Next topic

Eric

I need to have a formless Winsock control, so I'm using the Winsock control as a reference and the WithEvents keyword.  I've gotten it to load and connect, however the events aren't being triggered and I can't seem to figure out why.  

Here's my Winsock control class:


Option Explicit

Private WithEvents sckBNCS As Winsock

Private Sub Class_Initialize()
Set sckBNCS = New Winsock
End Sub

Public Sub Start()
With sckBNCS
   .Close
   .Protocol = sckTCPProtocol
   .RemoteHost = "63.240.202.121"
   .RemotePort = 6112
   .Connect
End With
End Sub

Private Sub sckBNCS_Connect()
Call modConsole.AppendText(2, 7, "Connected to Battle.net; negotiating...")
End Sub
Private Sub sckBNCS_Error(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)
Call modConsole.AppendText(2, 7, Description)
End Sub
Private Sub sckBNCS_Close()
Call modConsole.AppendText(2, 7, "Connection to Battle.net terminated remotely.")
End Sub

Private Sub Class_Terminate()
Set sckBNCS = Nothing
End Sub

The-FooL

In one of my bots, I use a third party winsock class that calls the APIs, uses events, and I have found to be safe.  It is called "CSocket" and can be found easily using google.  I have my own modified version that also acts as a packet buffer.  If you are interested you could pm.

TheMinistered

It is possible to use a winsock without it being used as a control.  It requires you have a developers version of winsock installed (i.e. visual basic installed), making a reference to it via project->reference, and using withevents.