Click here to Skip to main content
14,177,020 members
Click here to Skip to main content
Add your own
alternative version

Stats

67.4K views
2.2K downloads
45 bookmarked
Posted 16 May 2002
Licenced

Discover ISAPI. Feed Provider for Graphical Applets

, 16 May 2002
Rate this:
Please Sign up or sign in to vote.
Sample of using ISAPI extension to give online data to graphical applets.

Sample Image - Isapi_Applets.gif

Introduction

Some time ago, I implemented a data feed system from SQL database to some graphical applets. At the beginning, we decided a normal ASP script which read data and gave it to that applets would be useful. Unfortunately, it wasn't! The web server was crashed every time the number of simultaneous users on the site was more than 80-100 users and when a user tried to get larger data in an applet. For those reasons, we decided to move the feed to ISAPI DLL.

Advantages

  • The ASP server is freed by the calls from clients applets. In that way, the ASP will respond only to the normal site calls; the ASP will not produce any timeouts caused by applets calls.
  • Keeping the connection to the DB in the ISAPI cache, in that way all requests against DB don't lose time opening a connection, and will use the public open connection variable (CAdoDatabase m_AdoDB).
  • The ISAPI extension DLL is the best choice if you want to obtain the maximum number of simultaneous connections to the IIS web server or to provide huge quantities of HTML data.

Functionality

The ASP script loads the applet class and gives it some parameters, like colors, time interval of http's requests, web application URL, etc.

<applet codebase="../AspDemoFeed/Tools/OnlineScroll/CLASSES/JavaScroller/" 
archive="../AspDemoFeed/Tools/OnlineScroll/Scroller.jar" 
code="ScrollerStartUp.class" width="600"
height="20" VIEWASTEXT id="Scroller">
  param name="speed" value="3"
  param name="bgcolor" value="696969"
  param name="Font" value="Arial|1|16"
  param name="changeFontSize" value="11"
  param name="feedURL" value="
  <%=Application("WebURL")%>cgi-bin/IsapiDemoFeed.dll?GetOnlineScrollerData?"
  param name="updateInterval" value="20000"</applet>

The Java applet will make requests from the client's side to the web server HTTP using the received web URL parameter. The requests are made at equal intervals of time given in milliseconds by the updateInterval parameter. If you open the Java console on the client, you will see some messages like:

Loading data from 
http://localhost/projects/Articles/AspDemoFeed/cgi-bin/IsapiDemoFeed.dll?GetOnlineScrollerData?0&4

The ISAPI module responds to the HTTP hit with a format known by the applet, HTML stream:

0|2232160|453.4|2|14:19:06
1|576920|139.1|1|14:19:06
2|4006410|796.8|4|14:19:06
3|2511860|-31.5|2|14:19:06
4|2478810|529.2|0|14:19:06 

For each HTTP hit, the ISAPI module makes a request again to the SQL database, using the CAdoDatabase and CAdoRecordset classes from CodeProject site :). A minor modification was to keep the database connection as public variable. In each method, the record sets needed are opened and closed. An optimization is the use of GetString method of the AdoRecordset class, which returns formatted data text. Because the ISAPI DLL is harder to debug, more attention must be given to capturing errors, handled with try/catch macros.

try
{
  CAdoRecordset* AdoRS = new CAdoRecordset;          //create a recordset variable 
  if ( DBConnectionOpen( m_bstrConnectionString ) )  //look at db connection to be online
  { 						                         //open the recordset
    if ( AdoRS->Open(m_AdoDB.GetActiveConnection(), bstrSTMT, adOpenForwardOnly, 
		adLockReadOnly, adUseClient ) )              //here the disc params
    {
      if (!AdoRS->IsEof())                           //look if we have records
        varOutput = AdoRS->GetString("|", "\n", 0 );			
      else
        varOutput = "0 0 0 0 0 ";
      AdoRS->Close();                                //close the recordset 
      if (AdoRS)
        delete AdoRS;
    }
    else                                             //set the custom error
    {
      wsprintf(wcOut,"Encountered Error:<br>%s<br>
      %s<br>%s<br>%s<br>","MyFunction" 
         (LPCTSTR)m_AdoDB.GetLastError(), "RS isnt open", bstrSTMT );
      *pCtxt << wcOut ;
      return;
    } 
  }
  else                                               //set the custom error
  {
    wsprintf(wcOut, "Encountered Error:<br>%s<br>
    %s<br>%s<br>%s<br>","GetMarketMapData", 
    (LPCTSTR)m_AdoDB.GetLastError(), "DB isn't open", bstrSTMT );
    *pCtxt << wcOut ;	
    return;
  }
}
catch(_com_error err)
{ 	
  wsprintf(wcOut, "Encountered Error :<br>
  %s<br>%d<br>%s<br>", (LPSTR)err.Description(), 
     err.Error(), (LPSTR)err.ErrorMessage() );
  *pCtxt << wcOut ;
  return;
}
*pCtxt << varOutput;                                 //here is the output

IMPORTANT: To test the feed, you must make updates on the values of the tblOnline* tables. The updates will be reflectied online instantaneously in the Online tables and scrolling applets. To see how it works with Intraday charts applets make inserts in tblIntraday* tables. Those applets look permanently at those tables and update the values in cells and points on the charts.

Install

  • The ASP connection string are located in the Includes\_incConnectionOn.asp file.
    cnx.Provider = "sqloledb"
    	cnx.Open "Data Source=andi;Initial Catalog=ArticlesIsapiFeed;", "sa", "" 
  • The ISAPI connection string is located in IsapiDemoFeed.cpp file, on the constructor:
    m_bstrConnectionString="Provider=SQLOLEDB;Data Source=andi;Initial Catalog=ArticlesIsapiFeed;
    	User ID=sa;Password=;"; 
  • Copy the folder "AspDemoFeed" under your web site and make it ASP application, to work the session and
    application ASP objects.
  • Give "Scripts and Executables" Execute Permission to "cgi-bin" directory of "AspDemoFeed" web application.
    In that way, the ISS web server will be able to execute the IsapiDemoFeed.dll.
  • To install the database on your SQL server, select restore database option on SQL Server Enterprise Manager and choose the "DB/ArticlesIsapiFeed.bak" file backup. The name of database is ArticlesIsapiFeed.

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.

Share

About the Author

Adrian Bacaianu
Web Developer
Romania Romania
I make programming for over 4 years and extensive experience in C++, ASP, Pascal, MFC, COM+, ATL, TCP/IP, HTTP protocols, XML, XSL, SOAP and SQL.
For the last 2 years i working extensively at the background of financial sites (databases, n tier architecture).

I’m available for contracts and/or outsourcing (<Adrian Bacaianu>adrian_bacaianu@yahoo.com).

You may also be interested in...

Comments and Discussions

 
QuestionC# version Pin
Sing Abend30-Oct-07 6:40
memberSing Abend30-Oct-07 6:40 
Answer[Message Removed] Pin
immetoz1-Oct-08 9:41
memberimmetoz1-Oct-08 9:41 
QuestionI want to know the applet's source code Pin
zhaojicheng12-Jul-06 15:12
memberzhaojicheng12-Jul-06 15:12 
GeneralVery good work Pin
Chinese Coder6-Apr-06 20:33
memberChinese Coder6-Apr-06 20:33 
GeneralIt's working good ! Pin
3-Jul-02 0:40
suss3-Jul-02 0:40 
GeneralRe: It's working good ! Pin
Adrian Bacaianu3-Jul-02 0:48
memberAdrian Bacaianu3-Jul-02 0:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190526.1 | Last Updated 17 May 2002
Article Copyright 2002 by Adrian Bacaianu
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid