Results 1 to 5 of 5

Thread: Need a sample of code.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    128

    Need a sample of code.

    I need some code for winsock, I couldnt find it anywhere.
    If the connection is dropped, it connects to a different server. But I have 4 servers I want to switch around.

    So lets say one is

    z.z.z.z and it fails it goes to
    y.y.y.y and it fails it goes to
    x.x.x.x and it fails it goes to
    w.w.w.w and if it fails to goes back to z.z.z.z and so on and so forth.

    Help?

  2. #2
    Lively Member
    Join Date
    Oct 2006
    Posts
    81

    Re: Need a sample of code.

    make a string array for those 4 servers and 1 integer variable.. Connect to 1st address in array and set integer value to 1. Then check winsock state, if the connection is not made then close winsock and jump to next server in array (array(yourInteger + 1). and so on.. If yourInteger=4 then Yourinteger=1 again.. To check if server is working you can use Winsock_Connect event, and a timer for timeout.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    128

    Re: Need a sample of code.

    Example please.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Need a sample of code.

    Something like
    VB Code:
    1. Dim sServer As String(4)
    2.  
    3. Private Sub Form_Activate()
    4.  
    5.   sServer(0) = "z.z.z.z"
    6.   sServer(1) = "y.y.y.y"
    7.   sServer(2) = "x.x.x.x"
    8.   sServer(3) = "w.w.w.w"
    9.  
    10. End Sub
    11.  
    12. Private Sub ConnectToServer()
    13. Dim s As String, i As Integer
    14.  
    15.   Do
    16.     ConnectToServer(sServer(i))
    17.     if ConnectedToServer Then Exit Do
    18.     i = i + 1
    19.     If i = 4 Then i = 0
    20.   While Not ConnectedToServer
    21.  
    22. 'rest of code if connected
    23.  
    24. End Sub
    25.  
    26. Private Sub ConnectToServer(sServerName As String)
    27. 'code to connect to server
    28. End Sub
    29.  
    30. Private Function ConnectedToServer() As Boolean
    31. 'code to determine whether we're connected to server
    32. 'wait while we're connecting - we should get either a connection or a timeout
    33.   ConnectedToServer = 'True if we connected, False if we timed out
    34. End Function
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    128

    Re: Need a sample of code.

    Hmm, what about if we dont recieve data it switches to the next server?

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