SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index


Chapter 19
Writing Network Applications and Accessing Devices

SheerPower 4GL includes a number of network-based extensions for accessing data from webpages and sending email.

19.1 Accessing Data from Webpages

FORMAT:


  open ch #num: name 'http://url' 

EXAMPLE:

Example 19-1 Accessing data from webpages

  open #1: name 'http://www.ttinet.com/sheerpower/sample.txt' 
  for count = 1 to 100 
    line input #1, eof eof?: rec$ 
    if eof? then exit for
    print count; tab(10); rec$ 
  next count 
  close #1 
  end

PURPOSE:

To access raw HTML data from anywhere across the Internet.

DESCRIPTION:

The html:// file open option allows programs complete access to raw HTML data. This data can then be used to do things like get stock quotes, read news headlines, and fetch data from SheerPower handlers. For more see Section 19.3, Webserver CGI Interface.

19.2 Sending Email

FORMAT:


  email$ = 'mailto://'       + sendto$       + 
            '?subject='      + subject$      + 
            '&mailfrom='     + mailfrom$     + 
            '&replyto='      + replyto$      + 
            '&friendlyname=' + friendlyname$ + 
            '&cc='           + cc$           + 
            '&server='       + servername$   + 
            '&username='     + username$     + 
            '&password='     + password$ 
            
  open file email_ch: name email$, access output 
  print #email_ch: 'Text of email.' 
  print #email_ch: 'More text of email.' 
  print #email_ch: 'End of email.' 
  close #email_ch 
  
Where: 
 
  sendto$       = email recipient 
  subject$      = subject line 
  mailfrom$     = who this email will claim it is from 
  replyto$      = the "reply" email address if different from the "mailfrom$" address 
  friendlyname$ = the display name seen by the recipient (i.e. From: "Support" <support@ttinet.com>) 
  cc$           = recipient to be copied on the email 
  servername$   = SMTP server that handles outgoing emails 
  username$     = SMTP server username (if outgoing authentication is required) 
  password$     = SMTP server password (if outgoing authentication is required) 

EXAMPLE:

Example 19-2 Sending Email

  mailform$ = '<form>' 
  mailform$ = mailform$ + 'From: <input type=text name=from ' + 
    'value="Sender email address"><br><br>' 
  mailform$ = mailform$ + 'Reply To: <input type=text name=reply ' + 
    'value="Reply To email address"><br><br>' 
  mailform$ = mailform$ + 'Friendly Name: <input type=text name=display ' + 
    'value="Friendly (display) Name"><br><br>' 
  mailform$ = mailform$ + 'To: <input type=text name=to ' + 
    'value="Recipient email address"><br><br>' 
  mailform$ = mailform$ + 'Server: <input type=text name=server ' + 
    'value="SMTP server name"><br><br>' 
  mailform$ = mailform$ + 'Subject: <input type=text name=subject ' + 
   'value="Subject line"><br><br>' 
  mailform$ = mailform$ + 'Text: <br><textarea name=body rows=5 cols=60>' 
  mailform$ = mailform$ + 'Type in your text here.</textarea><br><br>' 
  mailform$ = mailform$ + '<input type=submit name=submit value="Send Email">' 
  mailform$ = mailform$ + '<input type=submit name=exit value="Cancel">' 
  mailform$ = mailform$ + '</form>' 
  line input dialogbox mailform$: data$ 
  
  for item = 1 to pieces(data$, chr$(26)) 
    z0$    = piece$(data$, item, chr$(26)) 
    name$  = element$(z0$, 1, '=') 
    value$ = element$(z0$, 2, '=') 
    
  select case name$ 
    case 'from' 
      mailfrom$ = value$ 
    case 'reply' 
      replyto$ = value$ 
    case 'display' 
      friendlyname$ = value$ 
    case 'to' 
      sendto$ = value$ 
    case 'server' 
      servername$ = value$ 
    case 'body' 
      text$ = value$ 
    case 'subject' 
      subject$ = value$ 
    case else
  end select
  next item                
  
  email$ = 'mailto://' + sendto$ + '?subject=' + subject$ +
           '&mailfrom=' + mailfrom$ + '&replyto=' + replyto$ + 
           '&friendlyname=' + friendlyname$ + '&server=' + servername$ + 
           '&wait'
                   
  message 'Sending...' 
  open #1: name email$, access output 
    print #1: text$ 
  close #1 
  message 'Sent!' 
end

PURPOSE:

To send emails.

DESCRIPTION:

When sending email, a number of optional parameters are supported.

Table 19-1 Sending Email - Optional Parameters Supported
  cc to copy another recipient to receive the email. To cc more than 1 recipient, use multiple CC options: &cc=someone@somewhere.com&cc=someone_else@somewhere.com
  emailfrom default to the email address in Outlook Express or the value of sheerpower$emailfrom
  replyto to specify a "reply to" email address that is different from the emailfrom email address
  friendlyname the name that is displayed to the recipient beside your email address
  server default to the SMTP server used by Outlook Express or the value of the logical sheerpower$server
  wait wait for email send to be completed
  nowait queue the email for sending as time permits
  timeout default is 30 second timeout. If we cannot reach the email server in this amount of time, abort the email sending.
  username and password when the SMTP server requires authentication, use these parameters to enter the username and password.
  attach=file_to_attach.xxx attach a file to this email. To attach more than one file, use multiple ATTACH options: attach=file1.xxx&attach=file2.xxx

Note

The start of the parameter list begins with a ? (question mark), and each parameter is separated by an & (ampersand).

Emails are queued for sending when the file is closed. If WAIT was specified, then SheerPower waits until the email is delivered before continuing processing. The default is NOWAIT.

For high reliability on sending emails with SheerPower 4GL, the SMTP server should be either on the same server as SheerPower or at least on the same LAN. This is because the SheerPower 4GL email handler is not a full email system that endlessly tries to send out emails even if the application has terminated.

The best use for the SheerPower email facility is:

SheerPower --> SMTP server (local one) --> Internet for delivery

This way there will be very few delays and reliability will be highest.

19.3 Webserver CGI Interface

Preparation

SheerPower applications can easily be "web-enabled" through its simple CGI Interface. The CGI interface works with SheerPower's own webserver program, SPINS webserver. For more information on SPINS webserver, see Chapter 18, SheerPower Internet Services (SPINS) Webserver.

19.3.1 SheerPower 4GL CGI Interface Sample Program

The sample CGI program eval_handler.spsrc is located in:


  c:\sheerpower\sphandler 

The webpage instructions that go along with the sample program is located in the same folder, and is called cgi.html.

19.3.2 Testing the CGI Interface

To use the CGI interface in SheerPower, SPINS Webserver must be running. If the Microsoft IIS webserver is running, it needs to be stopped, or ports configured to run both webservers at the same time. Instructions are found here - Section 18.1.3, Specify a Different Port Number.

To continue with this test, double-click on the EVAL_HANDLER.SPSRC file. This runs the EVAL_HANDLER program. This program file is located in:

c:\sheerpower\sphandlers\eval_handler.spsrc

After the EVAL_HANDLER has been started, you can try the FORM below.

After entering an expression, press the ENTER key. To get back to this webpage, click on the browser's BACK button.

Enter an expression, like sin(355/113) then press the ENTER key:

If the form does not work..

If this form did not work correctly for you, see Appendix L, Troubleshooting the CGI Interface.

How this form works

Each time anyone enters an expression to evaluate (like 2+3), their browser sends the data to your SPINS webserver along with a handler name. In this example, the handler name is EVAL. The SPINS websever then passes the data to the EVAL_HANDLER.SPSRC SheerPower program. The EVAL_HANDLER handles the request, figures out the result, and sends the result back to the SPINS server. The SPINS server then sends the result back to the browser.

Important Note on the Handler Name

The handler name defined in the source code MUST be defined in UPPER CASE.


Previous Next Contents Index