Beruflich Dokumente
Kultur Dokumente
how to install tntnet build and run your first application explanation of this first application further readings !I"
Tntnet is developped and tested with linux. It is known to run on Sun Solaris, IB and freeBS#.
Installation
$or installing Tntnet you need to install cxxtools before. %ou find cxxtools on the tntnet ho&epage http:''www.tntnet.org'download.h&s and install it with:
tar xzf cxxtools-2.0.tar.gz cd cxxtools-2.0 ./configure make su -c 'make install'
To build the application change to the new directory and execute /&ake-. To run the application enter /tntnet (c tntnet.conf-. )ow you can start your 0ebbrowser and navigate to http:''localhost:1222'&yfirstpro+ect. %ou can see the result of your first running tntnet(application, which prints the na&e of the application.
-&yfirstpro+ect. and our shared library -&yfirstpro+ect.so.. The co&ponent(identifier is then &yfirstpro+ect:&yfirstpro+ect . So - ap;rl. tells tntnet to call this co&ponent, when the url 'test.ht&l is requested.
)ext we co&pile the &odified webpage including the picture and link everything together. 0e need to tell the ecpp(co&piler 5 ecppc), that the picture is a binary file and which &i&e(type to generate. The flag (b tells ecppc not to look for tags like =>...>?. The co&ponent needs to tell the browser the &i&e(type which is -i&age'+pg. for your picture. The option -m is used to tell ecppc the &i&e(type. The picture will be co&piled into the co&ponent.
ecppc myfirstproject.ecpp g$$ -c -f%&' myfirstproject.cpp ecppc - -m image/jpeg picture.jpg g$$ -c -f%&' picture.cpp g$$ -o myfirstproject.so -shared myfirstproject.o picture.o -lecpp
to:
myfirstproject.so( myfirstproject.o picture.o
Before tntnet is started it is necessary to extend our configuration. Tntnet needs to know, that -picture.+pg. is found in the shared library -&yfirstpro+ect.so.. @ur new tntnet.conf looks like this:
)ap*rl /myfirstproject.html myfirstproject+myfirstproject
)ow we start our &odified webapplication which is found in &yfirstpro+ect.so. Start tntnet like before and look at the &odified page including your i&age.
*very request will be checked by tntnet for &atching the first of all regular expressions which are defined. *very request with the suffix -.ht&l. or -.+pg. &akes tntnet to look for a co&ponent with the basena&e of the request. @k B there is one funny thing in our configuration: we get our picture with http:''localhost:1222'picture.ht&l. But tntnet does not care and nor does the browser.
<p> <2 arg! 2> $ <2 arg2 2> " 9 if /result "" 0.01 3 nothing 9 8 else 3 <2 result 2> 9 8 </p> </ ody> </html>
aybe we should call it calc.ecpp. Sounds like a better na&e for a little calculator. But to be a real calculator the user should be able to enter the values. There is a solution to this, so go on reading.
rocessing parameters
Ct&l has for&s for dealing with user input. $or&s send their values to a web application. The application needs to receive these values as para&eters. Tntnet supports this by using the ecpp(tags < ar!s> ... <" ar!s> which enclose a para&eter definition. <et8s start with a si&ple exa&ple:
<9args> namefield6 </9args> <html>< ody> <form> :hat's your name; <input type"#text# name"#namefield#> <input type"#su mit#> </form> <hr> <ello <2 namefield 2> </ ody></html>
0e put a variablena&e into an args(block. This defines a 933 variable of type std::strin!, which receives the value of the request para&eter. The first ti&e we call our application, there are no para&eters, so 8na&efield8 is an e&pty string. It is possible to define so&e an non(e&pty default value by changing the definition to:
<9args> namefield " =:orld>#6 </9args>
The first ti&e our application is called we get this fa&ous -Cello 0orldD.(output 5sorry that it took so long until you get it6.
)ow we know all instru&ents which are needed to create a slightly &ore functional calculator:
<9args> arg!6 arg26 </9args> <3 dou le 5!? 526 std((istringstream s!/arg!16 s! >> 5!6 std((istringstream s2/arg216 s2 >> 526 8> <html>< ody> <form> <input type"#text# name"#arg!# 5alue"#<2arg!2>#> $ <input type"#text# name"#arg2# 5alue"#<2arg22>#> 9 if /s! @@ s21 3 // if oth input-streams 4ere successful extracting 5alues " <2 5! $ 52 2> 9 8 </form> </ ody></html>
)ow we create E pages page1.ecpp to page4.ecpp with so&e content. 0e want our &enu to be on each of our pages and the following code shows how the &enu( co&ponent is e&bedded. This is page F:
<html> < ody> <ta le> <tr> <td><@ =menu# @></td> <td><h!><ere is page !</h!></td> </tr> </ta le> </ ody> </html>
BCDE'FG"page!.o page2.o page7.o pageA.o menu.o ''"g$$ 'HH.,IJG"-f%&' 9.cpp 9.h( 9.ecpp ecppc 2< pages.so( 2/BCDE'FG1 g$$ -o 2+ -shared -ltntnet 2K
The configuration does not differ too &uch fro& the first exa&ple. Aust replace :&yfirstpro+ect with :pages, because our &odule na&e is now pages.so instead of &yfirstpro+ect.so. 9all -&ake. to co&pile it and as usual run the application with -tntnet (c tntnet.conf.. ! block <& ... &> contains a subco&ponent(call. In our si&ple case we have a nor&al 933(string(constant here. It can be also a variable or a functioncall, which returns a std::string.
"urther #eadings
tntnet users guide 5tntnet.pdf6 Tntnet configuration(reference 5tntnet(configuration.pdf6 The de&o progra&s in directory -sdk'de&os.