Asynchronous Read in ASP

Is there a way to do a SYNCHRONOUS read in ASP?  I want to be able to call another page and wait for it to finish processing, and possibly return me some data, before proceeding with my other task?

bonggoyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
clockwatcherConnect With a Mentor Commented:
I think you've got client-side development mixed up with server-side development.  The winsock or internet transfer control wouldn't be used client-side, you'd use it in a DLL server-side.

I would hardly call ServerObjects a small company in regards to ASP component development.  Their components are some of the most widely used ASP components available today.  Dimac puts out the JMail component which is probably the second or third most popular email component available.  But, certainly if your client doesn't mind paying for you to re-invent the wheel that decision is yours to make.

The fact that you're asking questions about if it's even possible to do with API calls means to me that you've got a long road of development ahead of you.  If you don't know the Winsock API that well, then how easy it's going to be to write is going to depend upon your C++ and ATL skills.  There is a reason that the Winsock and InternetTransfer Control exist after all.

Personally, if I couldn't use perl-- although, I hardly see perl which is under the GNU license just up and disappearing--, and if I'd never done any java development and didn't have a copy of J++, then I'd drop an internet transfer control into a VB COM DLL and use it.

Here's sample code.  Create a VB ActiveX DLL, add a Form (call it frmContainer) -- it's never going to be visible, it's just being used as a container for the Internet Transfer Control--, drop an Internet Transfer Control into it.  Add the following code to your class module and there you go.

Private inetControlContainer As frmContainer

Public Function GetURL(url As Variant) As Variant
    With inetControlContainer.Inet1
        GetURL = .OpenURL(CStr(url))
    End With
End Function

Private Sub Class_Initialize()
   
    Set inetControlContainer = New frmContainer
   
End Sub

Private Sub Class_Terminate()
   
    Set inetControlContainer = Nothing
   
End Sub

Assuming the code above was in a project called Clockwatcher and the class module was called HTTPGet.  The following ASP code would return the Yahoo page.


<%

 set myRequest = server.createobject("Clockwatcher.HTTPGet")
 mypage = myRequest.getURL("HTTP://www.yahoo.com/")

 response.write mypage

 set myRequest = nothing

%>

A working example of the above is at:

  http://experts-exchange.yahright.com/geturl/geturl.asp.

You can download the whole project at:

  http://experts-exchange.yahright.com/geturl/geturlproject.zip
0
 
bonggoyAuthor Commented:
Edited text of question.
0
 
bonggoyAuthor Commented:
Edited text of question.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
bonggoyAuthor Commented:
Edited text of question.
0
 
bonggoyAuthor Commented:
Adjusted points to 150
0
 
AemerginCommented:
IIS 4.0 cannot do it, but IIS 5.0 with ASP 3.0 can handle it using "Server.Execute", a new method of the server object. This will do exactly what you're looking for.

Windows 2000 is the way to go for ASP developers - ASP 3.0 handles things in a much more elegant manner, like "Server.Transfer" instead of "Response.Redirect". Much more efficiant code, and on top of that, it runs a bit faster too (in my experience).

You might also look into using w3 Sockets from www.dimac.net. I've heard that with the right use of wrappers, you can kind of do the same thing with that component.

Hope any or all of this helps!

-Aemergin
0
 
clockwatcherCommented:
Check out ASPHttp from ServerObjects.  From the way you worded your question, that sounds like what you are trying to do.

  http://www.serverobjects.com/products.htm#asphttp

0
 
clockwatcherCommented:
Actually, after checking the title of your question I'm unsure now whether you want to do an async or sync read.

Your title says asynchronous, but your question deals with synchronous.

Anywyay, ASPHttp is synchronous.
0
 
bonggoyAuthor Commented:
sorry it's suppose to be SYNCHRONOUS.  my mistake.
0
 
bonggoyAuthor Commented:
This question has a deletion request Pending
0
 
bonggoyAuthor Commented:
I need to be able to do synchronous read in IIS4; IIS5 is for win2k, I don't wan't to use a third party product and no ActiveX control.  If you have any other idea on how to do it, maybe an api call (example code will be great), I would gladly award all my available points.
0
 
AemerginCommented:
This question no longer is pending deletion
0
 
AemerginCommented:
>>Is there a way to do a SYNCHRONOUS read in ASP?  I want to be able to call another page and wait for it to finish processing, and possibly return me some data, before proceeding with my other task?


Deleting this question after it has been clearly answered seems odd. You asked "Is there a way?" -- you were supplied with three different ways.

And now a fourth answer -- there is no way to do it with an API call in IIS 4.0. You will either have to register a component, install IIS 5.0 (Win2k), or live without the ability to do a synchronous read.

-Aemergin
0
 
bonggoyAuthor Commented:
I admit that I didn't state what I really wanted.  I am not too fluent in english as it is not my first language and that's the reason for the confusion.  For that I am terribly sorry.

As for your answer of Execute statement in ASP3, I am quite aware of that capability and unfortunately IIS5/ASP3 is not an option owing to win2k.  

As for deleting the question, I don't have any problem awarding points.  It's just that I feel that I did not get the answer I am looking for.  

Again, I will gladly award the points and even give all my points as long as I feel that my question was answered the way I wanted it to be.

In regards to the question, I have basically given up on this approach (sync read on asp), I am now trying to do an DCOM call across the Internet.  That's the reason I am deleting the question.  If this is not the right way of doing it then, I am asking the EE administrator to rollback my request for delete.  I will just wait for the answer I am looking for.

for the fourth suggestion, I am thinking of some sort of socket api calls that i can use.  I could always wrap it up in a COM object and use that COM object from my asp page.  I am also aware of java security (or was it network api) calls wherein you can basically open a socket, send data through it and wait for response.  Right now this is not an option for because of clients requirement.
0
 
clockwatcherCommented:
You explicitly state that you don't want to use an ActiveX component.  But, you then go on to say that you have no problem creating a COM component to wrap the API calls???

What is you're objection to using third-party controls?  If it's cost, you can use Dimac's w3 Socket control-- it's free.  You'll have to hand-code the HTTP request and make a socket call, but it will do what you're asking.

  http://tech.dimac.net/

I don't know why you'd want to re-invent the wheel, but if you want to write wrappers for Winsock API, I guess that's up to you.  You've got the Winsock control and the INetTransfer Control to name just two examples that are much higher abstractions than the API.

If you know java and have J++, it's ridiculously easy to create a COM component using java that does what you need.

You could install ActiveState's perl (http://www.activestate.com) and use perlscript from within your ASP page to pull the other page-- again that's a no-cost solution (perl is free).

There are any number of ways to do what you're asking in your original question, but perhaps I'm not understanding what it is you really want to do.  It sounds like all you want to do is--
 
   1) request a page from within your script
   2) block until the request has returned results
   3) process/filter those results
   4) return something based upon those results

That's easy and can be done with any of the methods I outlined above.  It's basically a one-liner in a perl script.

<% @Language="VBScript" %>
<script language="perlscript" runat="server">
sub getPage {
  use LWP::Simple;
  return get("http://www.somewhere.com/mypage.asp")
}
</script>

<%
  myresults = getPage()
  response.write myresults
%>
0
 
bonggoyAuthor Commented:
I said I don't want to use ActiveX controls (which to me means .ocx file) and not ActiveX component.  The page needs to run in both Netscape and IE without additional plugin.

I don't want to use third party controls, particularly those coming from a not well established company.  I have nothing againts small company.   It's just that we had several experience before of using really great third party controls and after a few years the company folded up and we ended up rewriting everything the control did when we upgraded our system.

If perlscript is natively supported in IIS4/ASP2 (is it?), I will gladly use that.  I am looking for a solution that won't need me to install third party control/software.  I am open to suggestions, it's just that my decision is basically tied up to the clients requirement.

0
 
bonggoyAuthor Commented:
I said I don't want to use ActiveX controls (which to me means .ocx file) and not ActiveX component.  The page needs to run in both Netscape and IE without additional plugin.

I don't want to use third party controls, particularly those coming from a not well established company.  I have nothing againts small company.   It's just that we had several experience before of using really great third party controls and after a few years the company folded up and we ended up rewriting everything the control did when we upgraded our system.

If perlscript is natively supported in IIS4/ASP2 (is it?), I will gladly use that.  I am looking for a solution that won't need me to install third party control/software.  I am open to suggestions, it's just that my decision is basically tied up to the clients requirement.

0
 
bonggoyAuthor Commented:
This looks like a good suggestion.  One question though, will there be any effect if there's a form included on the activex dll.  Tradionally, at least in my case, I don't usually include any ui (form, msgbox, etc) in an activex server.  I guess i'm just worried that there will be a drawback or a negative effect.

Lastly, I would like to as much as I wanted to award points to each and everyone who answered my question, unfortunately, there's only one winner.  Anyways thanks to everyone.:)
0
 
bonggoyAuthor Commented:
I increased the points (all my available points) as I believe you've given an excellent answer.  A very simple yet elegant solution.  Much appreciation.
0
 
clockwatcherCommented:
It's probably not the most efficient way to do things.  But, sometimes simplicity more than makes up for efficiency. ;-)

I don't know of any other real drawbacks.  Like any other piece of VB code it depends upon a number of helper DLLs-- it needs to be packaged up to be installed on a server that doesn't have VB installed.  So distribution can be a bit of a pain, but that's a drawback of VB.

Personally, as I mentioned earlier, the VB solution I posted would probably be one of the last options I'd choose.  If I had to have source code, I'd go for a J++ COM DLL.  Java has built-in support for networking, so it's well suited to do this kind of thing.  Distribution is also much simpler-- if the server is running the latest JVM, you simply have to register the DLL.  The code is almost as simple as using the Internet Transfer Control.  Here's the equivalent in java of the VB code I posted earlier.

/**
 * This class is designed to be packaged with a COM DLL output format.
 * The class has no standard entry points, other than the constructor.
 * Public methods will be exposed as methods on the default COM interface.
 * @com.register ( clsid=612D49A3-D29E-11D3-A3F5-0020E00F5DD9, typelib=612D49A4-D29E-11D3-A3F5-0020E00F5DD9 )
 */
import java.net.*;
import java.io.*;

/**
 * @com.register ( clsid=96CA0A64-D2A0-11D3-A3F5-0020E00F5DD9, typelib=96CA0A63-D2A0-11D3-A3F5-0020E00F5DD9 )
 */
public class GetURL
{

   public String get(String getRequest) {
   
      URL myURL = null;
      try {
        myURL = new URL(getRequest);
      }
      catch (MalformedURLException e) {
        e.printStackTrace();
        return e.toString();
      }
   
      try {
        BufferedReader myReader = new BufferedReader(new InputStreamReader(myURL.openStream()));
        String str;
        String myBuffer = "";
        while ((str = myReader.readLine()) != null) {
           myBuffer += str;
        }
        return myBuffer;
      }
      catch (IOException e) {
        e.printStackTrace();
        return e.toString();
      }
   }
}
0
All Courses

From novice to tech pro — start learning today.