Articles 3D Audio Custom Controls General RB Graphics Hacks Mac OS X Menus Novelty Printing REALbasic 2005 REALbasic 2006 Registration Resources Reviews Serial Speech Sockets XML Video Resource Links News Current News February 2006 January 2006 December 2005 November 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 March 2005 ![]() REALbasic for Dummies by Erick Tejkowski ![]() Learning REALbasic through Applications REALbasic for Macintosh REALbasic Cross-Platform Application Development
Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander |
|
In this tutorial we're going to learn how to use the HTTPSocket class, a new feature in REALbasic 5.0, to show an image that we're going to download from the web in a canvas. As you might think, this is actually quite simple, but by no means is the HTTPSocket class "simple." Simple to use maybe, but what you can do with it is for the most part limitless. (We'll explore the HTTPSocket class in future tutorials.) The first step is to create a new project and drag a canvas to the window. Next, Control-Click or Right-Click on the main window. (Didn't know that contextual menu was there, did you?) Select "HTTPSocket" from "Add Control->Any->Socket Core...->TCPSocket...". After that, add two properties "Image as picture" . The HTTPSocket class allows your REALbasic application to connect to a web site, or more accurately, an HTTP server and send requests such as downloading a file or submitting a form. The HTTPSocket class has two settable properties, Address and Port, but since we're going to be using the Get method of the HTTPSocket class which requires an absolute URL anyway, we only need to be concerned about the port which is nearly always 80. So go ahead and put in 80 as the Port value for HTTPSocket1. For our project we're going to download an image from the ResExcellence website, located at "/realbasic/articles/old_articles/images_02/rbnewslogo.jpg". We're going to request the image from within the Open event of the canvas and then upon receiving it, we'll refresh the canvas so that it draws. The HTTPSocket.Get method requires only one parameter, an absolute URL to a file on the web site (and in our case this will be the URL in the previous paragraph), but it also has an optional parameter of type FolderItem which specifies a file to download the requested file to. If we don't supply a folderItem to the Get method, then REALbasic puts the data returned by the HTTP server into a string and calls the PageReceived event. On the contrary, if we do specify a file, the DownloadComplete event is fired which has - among others - a "file" parameter which is the file we specified in the Get call. Here's the one line of code for the Open event of the canvas. This line requests the image and downloads it to the "rbnewslogo.jpg" file in the "Temporary Items" folder. It's important that you specify an absolute URL whenever you use the Get method because if you don't you'll get an error code "103", but note that the file we download and the file we download it to do not have to have the same name. |
||||
|
||||||||||||||||||||||||||||||||
Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement.
[an error occurred while processing this directive]