Results 1 to 9 of 9

Thread: loop attemp connect on the client computer

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    7

    loop attemp connect on the client computer

    'Can I change?

    Private Sub Form_Load()
    Winsock1.Connect "192.168.1.1", "55501"
    End Sub

    'To this one?

    Private Sub Form_Load()
    Do
    Winsock1.Connect "192.168.1.1", "55501"
    Loop Until (Winsock1.State = sckConnected)
    End Sub

    tried it but i get and invalid operation at current state...

    just made a client sever program where the client sends a message to server when computer boots up... that's if the server computer boots up first... but when the client computer boots first server computer wont be able to gain connection to client computer anymore until client computer reboots..
    please any help would be much appreciated....

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: loop attemp connect on the client computer

    That looks like VB6 code. Are you sure that you're using VB.NET?

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    7

    Re: loop attemp connect on the client computer

    oops, sorry, i thought i was in VB6 forums.... but any way can you still help me with that? or i'll have to repost to vb6 forum again? sorry for me being a noob...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: loop attemp connect on the client computer

    I'll ask the mods to move this thread to the correct forum. Please don't repost.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    7

    Re: loop attemp connect on the client computer

    thanks a lot, hope to get more replies....

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: loop attemp connect on the client computer

    Welcome to VBForums

    Thread moved from the 'VB.Net' (VB2002 and later) forum to the 'VB6 and Earlier' forum

    (thanks for letting us know jmcilhinney )

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: loop attemp connect on the client computer

    looks like you need some delay, to stop the code from looping, until the connection attempt times out

    or better look into the events of the winsock control
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    7

    Re: loop attemp connect on the client computer

    tnx for the reply West, honestly i'm not good at coding, can you please give a sample code for me to get a start off? or just the right coding for this one?

    Private Sub Form_Load()
    Do
    Winsock1.Connect "192.168.1.1", "55501"
    Loop Until (Winsock1.State = sckConnected)
    End Sub

    tnx in advance...

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    7

    Re: loop attemp connect on the client computer

    ok guys, i,ve figured it out...
    Tnx west for the tip...just want to share it...^_^

    Private Sub Form_Load()
    Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Timer()
    label1.Caption = label1.Caption - 1
    If label1.Caption = 0 Then
    label1.Caption = 2
    If Winsock1.State <> sckConnected Then
    Winsock1.Close
    Winsock1.Connect "192.168.254.11", "55501"
    Else
    Timer1.Enabled = False
    End If
    End If
    End Sub

    I think this code is not bad for a week watching coding tutorials eh? ^_^

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