Results 1 to 3 of 3

Thread: Reconnecting Winsock

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    78

    Reconnecting Winsock

    Hi
    I've created an internet cafe manager software for my own internet cafe. I created to pieces of program; one for the server and the other one is for the clients. Sometimes I'm having problem with the network connection so I'm planning to add a feature in the client wherein it will reconnect to the server every time it fails to connect. I've tried to use a timer for the client to reconnect whenever a connection with the server doesn't established but I always got an error message.

    Sample Code:
    In the Form Load
    Dim rsClient As New ADODB.Recordset
    rsClient.Open "select * from tblClient order by TerminalNo", connClientDB,3,3

    Winsock1.RemoteHost = rsClient!IPAddress
    Winsock1.RemotePort = rsClient!Port
    Winsock1.Connect

    rsClient.Close
    Set rsClient = Nothing
    ----------------------------------------------------------------------
    In the Timer
    Dim rsClient As New ADODB.Recordset
    rsClient.Open "select * from tblClient order by TerminalNo", connClientDB,3,3

    If Winsock1.State <> sckConnected then
    Winsock1.RemoteHost = rsClient!IPAddress
    Winsock1.RemotePort = rsClient!Port
    Winsock1.Connect
    End If

    rsClient.Close
    Set rsClient = Nothing
    To become a PROFESSIONAL,
    Start from SCRATCH...

  2. #2
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Reconnecting Winsock

    What does the error in question say?

    Also, here's a reworked version of the second block that will help as well:

    Code:
    If Winsock1.State <> sckConnected then
        Winsock1.close
        Winsock1.Connect
    End If
    I took out the recordset lines, because they aren't needed once the winsock knows the address and port to connect to (which is provided in the first block of code.) Also, you need to close a winsock before trying to connect it to something; otherwise, it just sits in limbo and will throw an error if you try to connect to another computer, or accept a connection from anothe computer.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    78

    Re: Reconnecting Winsock

    Problem Solved!!!
    Thanks for the help
    To become a PROFESSIONAL,
    Start from SCRATCH...

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