Decal Development Forums Forum Index Decal Development Forums
www.decaldev.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Howto #1: Using the WebRequest.Get function using VB

 
Post new topic   Reply to topic    Decal Development Forums Forum Index -> AC FAQ's and Howtos (Archive)
View previous topic :: View next topic  
Author Message
Saitoh_TD



Joined: 19 Apr 2002
Posts: 110
Location: Cornfield, MO

PostPosted: Mon Apr 22, 2002 4:43 pm    Post subject: Howto #1: Using the WebRequest.Get function using VB Reply with quote

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 7:44 pm; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
bamboofoo



Joined: 27 Apr 2002
Posts: 17

PostPosted: Sun Apr 28, 2002 10:18 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
Saitoh_TD



Joined: 19 Apr 2002
Posts: 110
Location: Cornfield, MO

PostPosted: Tue Apr 30, 2002 6:56 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ascholer
Guest





PostPosted: Thu May 09, 2002 4:23 am    Post subject: Source for asynch Inet use Reply with quote

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.
Back to top
bamboofoo



Joined: 27 Apr 2002
Posts: 17

PostPosted: Thu May 09, 2002 9:39 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
Kaltemar



Joined: 08 Jun 2003
Posts: 38
Location: New Zealand

PostPosted: Tue Jun 17, 2003 1:03 am    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Sun May 08, 2005 5:24 pm    Post subject: Reply with quote

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?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Decal Development Forums Forum Index -> AC FAQ's and Howtos (Archive) All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group