Click to See Complete Forum and Search --> : ActiveX DLL's and the winsock component
TheLeeMan
Jan 24th, 2000, 06:59 PM
I am starting to experiment with creating my own activex components for use in my websites ASP pages.
I would like my new component to be able to send and receive information with other servers using Microsoft's WINSOCK control.
How could I accomplish this? I have tried
Winsock1 = Server.CreateObject("MSWinsockLib.Winsock")
but for some reason the object is not created successfully. How would I accomplish this? How would I take advantage of the controls events (DataArrival etc)? Thanks for your assistance.
TheLeeMan
[This message has been edited by TheLeeMan (edited 01-25-2000).]
Add a reference to the mswinsck.ocx.
And in the general declaration section use:
private withevents sckTest as MSwinsockLib.Winsock
Example:
Option Explicit
Private WithEvents sckTest As Winsock
Private Sub Class_Initialize()
Set sckTest = New MSWinsockLib.Winsock
End Sub
Private Sub sckTest_DataArrival(ByVal bytesTotal As Long)
End Sub
------------------
Vincent van den Braken
EMail: azzmodan@azzmodan.demon.nl
ICQ: 15440110 (http://www.icq.com/15440110)
Homepage: http://www.azzmodan.demon.nl
aalopes
Mar 16th, 2000, 09:09 AM
AzzModan,
I have posted some code on this site (new posting) based on the code sample you gave here.
Could you have a look at the code and see whats wrong ? Somehow the winsock control events are not raised I guess...thats why I can connect but there is no data received. Do you have any comments abouts something Im missing ?
Here is the code again...
Option Explicit
'Private objWERSSocket As New MSWinsockLib.Winsock
Private WithEvents objWERSSocket As MSWinsockLib.Winsock
Public sDump As String
Private sDataBack As String
Public Function ConnectToWERS() As Boolean
Dim sRequestHeader As String
Dim sRequestURL As String
Dim sURL As String
Dim blnRetValue As Boolean
objWERSSocket.Protocol = sckTCPProtocol
objWERSSocket.RemoteHost = "sdowning"
objWERSSocket.RemotePort = 80
Call objWERSSocket.Connect
While objWERSSocket.State <> 7
MsgBox "Before " & objWERSSocket.State
DoEvents
Wend
MsgBox "After " & objWERSSocket.State
sRequestHeader = "GET /livelink/livelink.exe?func=Personal.Tasks HTTP/1.0" & Chr(10)
sRequestHeader = sRequestHeader & "Content-type: application/x-www-form-urlencoded" & Chr(10)
sRequestHeader = sRequestHeader & "Content-length: " & Len(sRequestURL) & Chr(10) & Chr(10)
sURL = sRequestHeader
MsgBox sURL
Call objWERSSocket.SendData(sURL)
End Function
Private Sub Class_Terminate()
MsgBox objWERSSocket.BytesReceived
Set objWERSSocket = Nothing
End Sub
Private Sub objWERSSocket_DataArrival(ByVal bytesTotal As Long)
Call objWERSSocket.GetData(sDataBack, vbString)
'sDump = sDump & sDataBack
End Sub
Private Sub Class_Initialize()
Set objWERSSocket = New MSWinsockLib.Winsock
End Sub
Wolfie
Jun 18th, 2000, 06:48 PM
I am having the same problems, one thing I have learned is that the control acts funny when you set the remote port and remote host before calling the connect method. Rather do it all in one like:
objWERSSocket.Protocol = sckTCPProtocol
objWERSSocket.Connect "sdowning", 80
The events are still a nuisance to me, if you get that working, please let me know.
Cheers
Wolfie
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.