Results 1 to 3 of 3

Thread: [VB6] Problem with Winsock in Class module

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Location
    Paris
    Posts
    2

    [VB6] Problem with Winsock in Class module

    Hi all,

    I have a problem with Winsock in my application and I really don't know how to fix it. I'm developping a .dll for a web application by the way.

    I checked the box "Microsoft Winsock Control 6.0 (SP5)" in the Project>References menu.

    In the webclass, when I click a button, I create a Socket, set some information and try to connect
    VB Code:
    1. Dim mySocket As EPSocket
    2.         Set mySocket = New EPSocket
    3.         mySocket.mPort = 10000
    4.         mySocket.mServer = "localhost"
    5.         Call mySocket.CreateConnect
    I'm using a class called EPSocket because otherwise VB wouldn't let me create an object with the WithEvents declaration, which I need (at least I think I do).

    The EPSocket class:
    VB Code:
    1. Option Explicit
    2.  
    3. Private WithEvents oWinsock As MSWinsockLib.Winsock
    4.  
    5. Private mvarmServer As String
    6. Private mvarmPort As Integer
    7.  
    8. Public Property Let mPort(ByVal vData As Integer)
    9.     mvarmPort = vData
    10. End Property
    11.  
    12. Public Property Get mPort() As Integer
    13.     mPort = mvarmPort
    14. End Property
    15.  
    16. Public Property Let mServer(ByVal vData As String)
    17.     mvarmServer = vData
    18. End Property
    19.  
    20. Public Property Get mServer() As String
    21.     mServer = mvarmServer
    22. End Property
    23.  
    24. Private Sub Class_Initialize()
    25.     Set oWinsock = New MSWinsockLib.Winsock
    26. End Sub
    27.  
    28. Public Sub CreateConnect()
    29.  
    30.     oWinsock.Connect mvarmServer, mvarmPort
    31.  
    32. End Sub
    33.  
    34. Private Sub oWinsock_Connect()
    35.  
    36.     oWinsock.SendData CStr("Hello World")
    37.     oWinsock.Close
    38.    
    39. End Sub
    40.  
    41. Private Sub oWinsock_Close()
    42.     Set oWinsock = Nothing
    43. End Sub
    44.  
    45. Private Sub oWinsock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, _
    46. ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    47.  
    48.     Debug.Print Description
    49.  
    50. End Sub
    The problem is: the Socket is created without problem, the connection happens, but the oWinsock_Connect function is never run. I'm probably overlooking something really obvious, but I just can't figure it out. Any ideas?
    Thanks,
    Ilyas

  2. #2
    New Member
    Join Date
    Jul 2005
    Posts
    5

    Re: [VB6] Problem with Winsock in Class module

    try changing Call mySocket.CreateConnect to mySocket.Connect

    Not sure if this will help, you probably know more about what you're doing than i do... i've only been programming in winsock for like a day, and i suck at it

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Location
    Paris
    Posts
    2

    Re: [VB6] Problem with Winsock in Class module

    Thanks for your answer, but that's not the problem. The method CreateConnect is called all right, it's just that my class doesn't seem to be able to "see" or "trap" the events relative to the socket: connect, data_arrival, error... that kind of stuff.

    Cheers,
    Ilyas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width