![]() 3D 3D Photo Gallery (Part 1) 3D Photo Gallery (Part 2) Audio Poor Man's MIDI Make A Metronome iPod Tricks (Part 1) iPod Tricks (Part 2) iPod Tricks (Part 3) Laugh Track Machine Audio Player with Reverb Shepard Melody RB Phone Home Build a Drum Machine Custom Controls and Windows Double Click Listbox Draggable Metal Window Double Click Canvas Custom Buttons Custom Buttons Part II iTunes-style Listboxes Custom Controls General RB Scrolling Windows Using Mesage Dialogs Case-Sensitive Word Finder Introduction to Stacks Wiggle Window JPEG in PDF Listbox Checkboxes Background Applications Listbox Auto-Find Virtual Volumes Time Tracker Software Distribution (Part 1) Software Distribution (Part 2) Software Distribution (Part 3) Software Distribution (Part 4) Exceptions Tips and Tricks Text Clippings Made Easy Graphics Drawing a Simple Gradient The SpriteSurface: Space Game Image Spinner Cropping Graphics (Part 1) Cropping Graphics (Part 2) Cropping Graphics (Part 3) Cropping Graphics (Part 4) Shimmer Graphics Lissajous Figures Simple Screen Capture Vector Graphics Kaleidoscope Images Stegonography Spirals! Image Table RB Magnifying Lens Screen Capture Color Picker Tutorial Hacks Ghost Grab Speedy Mouse Extension iTunes Plugins iTunes Skinner Mac OS X Global Hot Key Event (Carbon Events) Login Welcomer (Carbon Events) Add/Remove Buttons Resizable Sheets Mac OS X Preferences Window Using Sheets in REALbasic Build a Bundle (Part 1) Build a Bundle (Part 2) Dock Your Passwords Mac OS X Debugging REALbasic Mac OS X Icon Tutorial Animate Your Dock RB and the Command Line Menus Window Menu Templates Menu Listbox Menu Novelty Guessing Game Calendar Trivia Tile Mixer Zip Code Finder Happy Valentine's Day Merlin Simulator (Part 1) Merlin Simulator (Part 2) Merlin Simulator (Part 3) Buzzword Machine AppleSoft BASIC Printing Print to PDF Registration Registration Code Validation Network Registration Codes Resources Picture Extractor (Part 1) Picture Extractor (Part 2) Serial Caller ID (Part 1) Caller ID (Part 2) Caller ID (Part 3) Speech Speech Recognition Socket Communication Easy Peer-to-Peer File Sharing MacPAD Version Checking Display Web Image In Canvas HTML IMG Tags Version Tracking Even Smarter Instant Messaging Web Tiler JavaScript and REALbasic Stock Ticker (Part I) Stock Ticker (Part 2) AIM Mate XML Manipulation Simple XML Introduction Video Big Brother Video Capture Note: All articles without a byline were written by Erick Tejkowski. When cleaning the site I removed them because the code differed from page to page, and I have yet to put them back in.
Tell us about a bad link. |
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. |
|||||
|
Please support ResExcellence by Visiting our Sponsors. One click makes a difference. |
||||||
|
|