Decal Development Forums

www.decaldev.com
It is currently Mon Apr 24, 2017 7:00 pm

All times are UTC - 5 hours [ DST ]




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
PostPosted: Mon Apr 22, 2002 5:43 pm 
Offline

Joined: Fri Apr 19, 2002 9:35 pm
Posts: 110
Location: Cornfield, MO
Howto: Using the WebRequest.Get function in Decal using Visual Basic

Definitions:

Post - Send data to a webpage with the data encoded in the call to the webpage
Get - Send data to a webpage by including it as parameters in the address
EDI - Electronic Data Interchange. It uses a delimiter to seperate string values. HI*Saitoh*10012
WAP - Wireless Access Protocol. Basically, shove tiny compressed tiny data instead of wasting bandwidth

Concepts:

WebRequest is basically the Microsoft INet control. While using the INet control causes AC to freeze, WebRequest works asyncronously, similiar to the winsock32.ocx. The Winsock control is meant for direct Client - Server interactions, while Webrequest is specialized for HTTP communications only.

Still, WebRequest makes an excellent function for retrieving, posting, and WAP-similiar tasks. In this example, I will be using an EDI format. You can use any format you desire, but I like the way I can use a SPLIT call to handle returned information. You could use space delitmitation though, which is when each value is set into an area of a certain length with appended spaces or zeros to fill the area.

Because of it's differences, WebRequest.Post is a different tutorial.

Header:

All we need here is to define our WebRequest control and perhaps a string to make calling the URL easier.

Code:

'Define a WebRequest Object
Private WithEvents MainWeb As DecalNet.WebRequest

'Our URL
Private MainUrl As String



Initialize:

Once again, we simply need to let our Plugin know that our WebRequest is there.

Code:

Set MainWeb = New DecalNet.WebRequest



Toss:

Now for the fun part. When you perform a WebRequest, it's basically like tossing a friend a set of colored balls and him tossing them back. You may toss red, blue, then green, but receive them back in a blue, red, green order. Behaviour like this is noted as "How the Internet Works". An AC example of this is the Update Vital Statistic packet. If you look at the protocol, you'll note that they recently added a numbered packet to help syncronized what should be displayed. Your plugin is no different, so be prepared for this.

So, how do I toss at the webserver?

Code:

'Set the URL
MainUrl = "http://www.myserver.com/cgi-bin/mypage.cgi?value=1"

'Get the URL
MainWeb.Get (MainUrl)



Easy, huh? Almost. When making ZyrcaNet, we found out that the WebRequest function behaves using Internet Explorer's ruleset. Why is that important? Because if your user has "Cache webpages", otherwise known as "Refresh webpages:", turn on, they will receive a cached version of your page without bothering to check if a new page is out there. This really can mess with CGI pages that are very dynamic. How to fix it?

Code:

MainUrl = "http://www.myserver.com/cgi-bin/mypage.cgi?value=1&random=" & Str(Rnd(200000))
MainWeb.Get (MainUrl)



By introducing a random number, even if your webpage doesn't catch the random variable, your WebRequest will be fooled into retrieving a new page.

Catch:

So, our request is out there. Instead of instantly retrieving the results like the Inet control, we need to create a Callback. This is not difficult, a callback is just a function that outside applications can use to say "Hey! Your crud is ready! *toss*". For our WebRequest this is known as ControlName_End.

Processing it is the tricky part. Remember how I said above that you don't know the order of which things are received? Using an EDI format makes sorting our returns simple. We just need to split the return and use the first value as our message type code.

Code:

Private Sub MainWeb_End(ByVal nResultCode As Long, ByVal strText As String)
'Create an array for our return
Dim Values() as string

'Our return is seperated by *'s, divide each part into an array
Values = Split(Strtext,"*")

'Get an uppercase version of the first value in Values
select case ucase(Values(0))
case "DO": 'Do stuff
case "CAST": 'Cast something
case "SAY": 'Say something
end select



Time to do something with the rest of the data returned. Since all of our data is returned via an array, all we really need to do is to use that data how we want.

Lets pretend that the returned EDI format for "CAST" is CAST*{spell number}*{Character Number". So, we'd get back something like "CAST*1293*1239502".

Back to our case statement:

Code:

case "Cast":
pluginsite.castspell(val(Values(1)), val(values(2)))



Summary:

Text in, text out. You can use this control for any HTTP communications. Instead of polling a CGI script, you could have it grab HTML from a website, strip off then control characters and redisplay it.

To get a webpage: Set URL->Get URL->Catch Return

_________________
- Navi - Navi II - Navi III -
http://www.saigumi.net
http://navi3.sourceforge.net


Last edited by Saitoh_TD on Sat Jul 06, 2002 8:44 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 28, 2002 11:18 am 
Offline

Joined: Sat Apr 27, 2002 11:11 am
Posts: 17
I'd just like to add....you can also use the Inet control asynchronously, without any problems that I have noticed whatsoever. The plugin in question downloads "news" from a server upon login, and hasn't had a problem with lockups, freezes, etc etc.

If anyone is interested in that, I'll post the code and some comments really quick...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 30, 2002 7:56 pm 
Offline

Joined: Fri Apr 19, 2002 9:35 pm
Posts: 110
Location: Cornfield, MO
While I've only used the inline version of the inet control, if it can do asynchronously, it would be a good alternative if you had to have the extra functionality that the control warrants.

Though, that means your installer has to include the additional external OCX/DLL and adds extra bulk. Also adding issues about versions and potential errors during installation. While there shouldn't be any, it's just a risk to note.

_________________
- Navi - Navi II - Navi III -
http://www.saigumi.net
http://navi3.sourceforge.net


Top
 Profile  
 
PostPosted: Thu May 09, 2002 5:23 am 
I would love to see your source for using an Inet control in asynch mode. I'm trying to do that myself and progress is slow.


Top
  
 
 Post subject:
PostPosted: Thu May 09, 2002 10:39 am 
Offline

Joined: Sat Apr 27, 2002 11:11 am
Posts: 17
Ok, first of all, to Saitoh, don't you still need to distribute the OCX for the WebBrowser control with your plugin? Or is that something distributed with IE (a potential issue for Netscape users...?)

Secondly, about using the Inet control asynchronously, I'll post some code later on this morning. A point to mention, though..

I have heard that the Inet control is SLOW over dialups. While I'm on an ADSL line, I've never noticed it being too slow (granted, I'm only recieving ONE packet of information....) I've thought about using it to UPDATE my plugin dynamically, without having to download a new installer/version and whatnot... I'm sure the limitations will present themselves there for sure.

acholer, are you using a dialup, broadband, or some "other" means of connecting! =)

I'll be posting in a new topic too....just to keep the replies off this one, and keep it nice and clear.
And the new topic is...:
HERE!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2003 2:03 am 
Offline

Joined: Sun Jun 08, 2003 2:43 am
Posts: 38
Location: New Zealand
If you feel like having the added power, including having the control NOT cache pages, you can use the Winsock control directly, allowing you to post any darn request you like to the server, in any form, with the tradeoff that you have to know HTTP (not HTML)


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 08, 2005 6:24 pm 
Hey Saitoh

I went through your instructions completely, but AC still temporary locks up when I communicate with a web server.

My I emptied my MainWeb_End sub thinking it may have been a problem with catching and interpreting the data but it's still locking up. Is WebRequest.Get supposed to work asynchronously?


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group