PDA

Click to See Complete Forum and Search --> : Winsock again


aalopes
Mar 16th, 2000, 08:37 AM
Im trying to make a COM object to "talk" to a server.
I invoke the ConnectToWERS() method and my winsock connects fine with State = 7 but it doesnt return me any data. Gives
BytesReceived = 0
neither can I trap the DataArrival event to see what happened.

If I try the same thing in a form-based .exe using winsock control, it works fine and gives data back.

Am I missing anything ? Or is it got anything to do with statelessness of the Object method calls. Statelessness Im trying to avoid by storing the data received back in the object feature sDataBack.

Pls help.

Allen.


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