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 "GET", 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 "I'm sorry, the chat service is unavailable at this time, please come back later.<br>Error:" & 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()