TALKING TO THE SERVER

At this lesson we will do an important step to our objective, the creation of the application that has the registering of students and a report, a list of them. We will create an easy application where the user types some words and this string goes to the server (our web-server: www.dmu.com) and returns. We are creating an "echo" from FLORIDA (USA), where we have our server.

We will change the default names of the controls. It's easy: type over the name at the "Object Viewer".

Typed the words in the TextBorder "Shout", we need to click the Button "Click". This object has glued the script:

| page parsedPage thebody clean wordCust |
wordCust:=(Shout1 getCharacters) copyReplaceAll: ' ' with:'_'. 
page:=HTTPSocket httpGet:'http://www.dmu.com/croquet/echo.aspx?thename=', wordCust.
parsedPage := HtmlParser parse: page. 
thebody := parsedPage body.
clean := thebody   contents at:1 .  
clean := clean  asString .
clean := clean copyReplaceAll: '[' with:''. 
clean := clean copyReplaceAll: ']' with:''. 
Echo setCharacters: clean.
Shout1 setCharacters:''.

Remember the tip about the automatic change of the name of a Control. Yours can have another names/versions ! In the video you will see the names: Shout4 and Echo3.

In the first line of code we capture the word typed and replace (if there are) any blank by the symbol: "_". We can't transmit blanks.

We are using, in the second line, the method httpGet of the Class HTTPSocket. (Cobalt has hundred of Classes. May be some day we will create a Quick Reference of the more important...). This method calls the ASPX program (echo.aspx) in the web server, sending the variable: thename having the content of the TextBorder Shout.

This ASPX program - we will see it soon - takes the value of the variable and add it after the string: "echo for =" and send it back to the machine of the user, but adding some aditional things that need to be cleaned.

The "answer" of the server will go to the variable: page.

The lines of code to "clean" the answer are :

                    thebody := parsedPage body.
                    clean := thebody   contents at:1 .  
                    clean := clean  asString .
                    clean := clean copyReplaceAll: '[' with:''. 
                    clean := clean copyReplaceAll: ']' with:''.

This 5 lines of code will be the same for any answer of an HTTP server.

The last line of the code sets the answer in the Echo TextBorder.

The ASPX program is coded in JavaScript and is uploaded to that path of our server:

<script language="JavaScript" runat="server">
function Page_Load(sender:Object, e:EventArgs):void{
 var thename=this.Request.Params["thename"];
 Response.Write("echo for = " + thename); 
}
</script>

We will not teach ASPX at this course. Only for you information:

If you like, you can do this exercice and use our server for the access to the ASPX script. Our server is free available for tests.

In the video we see that we have pasted the script, but needed to change the versions of Shout and Echo:




PREVIOUS LESSON NEXT LESSON
TABLE OF CONTENTS HOMEPAGE