Results 1 to 6 of 6

Thread: Creating a Winsock object

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    25

    Creating a Winsock object

    I am just trying to create a TCP/IP connection to a server. I am using the ActiveX Winsock provided by VB. This is my code:

    VB Code:
    1. Private tcpipclient As Winsock
    2. Private clientName As String
    3.  
    4.     Public Sub constructor(name As String)
    5.     clientName = name
    6.     Set tcpipclient = CreateObject("Winsock", clientName)
    7.     tcpipclient.RemoteHost = clientName
    8.     tcpipclient.RemotePort = 5000
    9.     Call tcpipclient.Connect
    10. End Sub

    It errors on the createObject:
    "Run-time error 429, ActiveX component cant create the object"

    This is in a class module, so there is not an object defined in a form. How should I create this winsock object?
    Last edited by McManCSU; Apr 29th, 2006 at 05:58 PM.

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,794

    Re: Creating a Winsock object

    Does it have to be in a class ?

  3. #3
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Creating a Winsock object

    You need to first Reference the Winsock object, to your project.

    Here some code to test, if it works you see the message I am now connected.
    Hope it helps

    Code:
    Private WithEvents tcpipclient As Winsock
    
    Private Sub tcpipclient_connect()
        MsgBox "Hi I am Now Connected"
    End Sub
    
    Private Sub Command1_Click()
        Set tcpipclient = New MSWinsockLib.Winsock
        tcpipclient.RemoteHost = "localhost"
        tcpipclient.RemotePort = 80
        tcpipclient.Connect
    End Sub
    When your dreams come true.
    On error resume pulling hair out.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    25

    Re: Creating a Winsock object

    It should be in a class because I am going to create multiple clients which are held in a collection, that way I can connect to each server induvidually from each client I create.

    I tried the code, but it complains about the 'new': Compile error, invalid use of new. Any other hints?

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,794

    Re: Creating a Winsock object

    Quote Originally Posted by McManCSU
    It should be in a class because I am going to create multiple clients which are held in a collection, that way I can connect to each server induvidually from each client I create.
    You can do that using a control array.

    Just give the control that you put on the form Index = 0, then use
    "Load winsock(winsock.UBound + 1)"
    To load a new control, and you can use it after that...

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    25

    Re: Creating a Winsock object

    Well, I have never used control arrays, and since my deadline time is nearing, I think I will avoid using them. This was my plan:

    Create 'nodes' which are physically located at some longitude/latitude position. I have one main program which talks to each one of the nodes individually, so the main program is the client (one instance per node), and each node is a server. I have a form which I specify each nodes' location. Therefore, each node is an object with certain attributes (a class), and I wanted to have each node maintain its own connection to the main program. Is there a way to create a TCP/IP connection to each node from the node class (which is not a form, cause I know you can create a TCP/IP connection box in forms)?

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