Content deleted Content added
Guidosalva (talk | contribs) mNo edit summary |
Yun Sun 423 (talk | contribs) |
||
Line 4:
== Example ==
As an example, we show an Echo client–server application: The client sends a message to the server and the server returns the same message to the client, where it is appended to a list of received messages. The application is simple and self-contained, and – despite all the limitations of short and synthetic examples – it gives us the chance to demonstrate
fun echo(item) server {▼
item▼
Listing 1. Echo application in Hop.js.<syntaxhighlight lang="lisp" line="1">
service echo() {
var input = <input type="text" />
return <html>
<body onload=~{
var ws = new WebSocket("ws://localhost:" + ${hop.port} + "/hop/ws")
ws.onmessage = function(event) { document.getElemenetById("list").appendChild(<li>${event.data}</li>) }
}>
<div>
${input}
<button onclick=~{ ws.send(${input}.value) }>Echo!</button>
</div>
<ul id="list" />
</body>
</html>
}
var wss = new WebSocketServer("ws")
wss.onconnection = function(event){
var ws = event.value
ws.onmessage = function(event) { ws.send(event.value) }
}
</syntaxhighlight>Listing 2. Echo application in Links.<syntaxhighlight lang="java" line="1">
▲ item
}
fun main() server {
page
<html>
<body>
<form l:onsubmit="{appendChildren(<li>{stringToXml(echo(item))}</li>, getNodeById("list"))}">
<input l:name="item" />
<button type="submit">Echo!</button>
</form>
<ul id="list" />
</body>
</html>
}
main()
</syntaxhighlight>
Listing 3. Echo application in Ur/Web.<syntaxhighlight lang="sml" line="1">
fun echo (item : string) = return item
fun main () =
let fun mkhtml list =
case list of
[] => <xml/>
| r :: list => <xml><li>{[r]}</li>{mkhtml list}</xml>
in
item <- source "";
list <- source [];
return <xml><body>
<div>
<ctextbox source={item} />
<buttonvalue="Echo!"onclick={fn =>
list' <- get list;
item' <- get item;
item' <- rpc (echo item');
set list (item' :: list')
}/>
</div>
<ul>
<dyn signal={
list' <- signal list;
return (mkhtml list')
}/>
</ul>
</body></xml>
end
</syntaxhighlight><br />
== List of multitier programming languages ==
|