Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round Robin DNS 1

Status
Not open for further replies.

Geordears

Technical User
Dec 10, 2002
5
CA
How do I set up a website to utilize a round robin dns. I'm not the network person just the web designer. They apparently are setting it up so it will do that for a backend chat program. The front end website (some info pages) is hosted on a separate server. They want it so when people want to log into the chat part when they use the logon button at the front end, it rotates the users between the 2 backend URLs. All I can find info for is 2 IP addresses with 1 URL. Is there and ASP code (or anything)I can attach to the logon button?






 
One question before I try to answer this, how do yu decide which URL a person is supposed to log into? Is it going to be random, or every odd person goes to one, every even person goes to another, or will one be primary and if it gets full/goes down people are directed to 2nd...
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Every odd to one and every even to another. But if one goes down they are all directed to the one still standing.
 
Ooh, a challenge :)

Ok, two more questions, I already have a pretty good idea though,
1) Is the login handled by the chat server or is the login form in the website and sends it to the chat server
1b) if the login page is on the website, not the chat server, is it already written in ASP?
2) What is the chat server? (website, applet, servlet, flash, java application, etc) and is it expecting any data from the web page or does the user just need to get directed to the correct URL?

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
All the website has to do direct someone to the logon page which is on the chat site on the backend server. They want to mirror the two machines. We have had a lot of ups and downs using Cogeco lately, so they set one up using Cogeco and one using Sympatico, so if say Cogeco goes down the site will still have sympatico internet access. So the first user needs to be directed to the Cogeco machine and the second the sympatico machine. One IP address 2 host names. Is that clear or muddled?
 
Hmm, well you could do this several ways, but here is one:
In your global.asa file set up an application variable. and initially set it to either true or false (won't matter).

Then in your ASP page read the value of the variable and set it to the opposite. If the variable was true we are going one directin, if the variable was false, we will go the other.
Code:
ie: pretend our server variable was named ServerPath
Dim srvUrl, srvDir
srvDir = Application("ServerPath")
Application("ServerPath") = Not Application("ServerPath")
If srvDir = True Then
   srvUrl = "[URL unfurl="true"]http://www.ourFirstMachine.com/"[/URL]
Else
   srvUrl = "[URL unfurl="true"]http://www.OurSecondMachine.com/"[/URL]
End If
This won't be absolutely perfect unless you get into locking and such and lock for both read and write before your two line variable assignment statement, then unlock right before your if stmt.

In either case, set the corresponding URL into a variable. Then we can use XMLHTTP to test if the connection is alive.
Basically what you will want to do is:
Code:
Response.Buffer = True
Dim objXMLHTTP, URL

' Create an xmlhttp object:
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")

URL = "[URL unfurl="true"]http://www.toddorg.com/news/Article0_Static.htm"[/URL]

' Opens the connection to the remote server.
objXMLHTTP.Open "GET", URL, False

' Actually Sends the request and returns the data:
objXMLHTTP.Send

If objXMLHTTP.status <> 200 Then
   'basically this means we couldn't retrieve the page, could be downed server, could be a failure to resolve DNS, etc
   'so in this case we will now check the other server
   objXMLHTTP.Close
   'set the URL variable to the other server, you'll know which was the first choice because you saved the value of the Application variable
   URL = ...
   objXMLHTTP.Open &quot;GET&quot;, URL, False
   objXMLHTTP.Send
   If objXMLHTTP.status <> 200 Then
      'uh oh, this URL failed too, could the server be down?
      'you could actually check for differant error codes like 404, etc or you could print out the statusText property from the XMLHTTP object as the error message
      Response.Write &quot;I'm sorry, the chat service is unavailable at this time, please come back later.<br>Error:&quot; & objXMLHTTP.statusText
   Else
      '2nd tried address worked, so write out your form tag with the value of the URL variable in the action attribute
   End If  'ends the second connection attempt
Else   'the first connection attempt was successful
   'write out the URL variable (with the originally chosen address still in it) into your action attribute of your form tag
End If


Now what could be done to speed up this process and also help balance the load, is instead of using the Application variable, automatically make a request to the server via both URLs. On the chat server have a generate web page that keeps track of people logged in and which domain name they came in on (can use ASP Request.ServerVariables collection to pull this from the page request header). Then the chat server's generated page could simply be two numbers:
Code:
#OnFirstUrl, #onSecondUrl

So you would do a double request to the server for the same (very small) page, then if neither fails (ie you have a choice which one to send them to) send them to the one with less users.

Hope this made some sense,
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
FAQ FAQ20-2863
= new Forums.Posting.General.GettingAnswers()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top