mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
reference: WebSocket
git-svn-id: svn://ultimatepp.org/upp/trunk@6708 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
f65a99f7ed
commit
5ba2e29db2
7 changed files with 79 additions and 1 deletions
4
reference/SplitterFrame/init
Normal file
4
reference/SplitterFrame/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _SplitterFrame_icpp_init_stub
|
||||
#define _SplitterFrame_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#endif
|
||||
27
reference/WebSocket/WebSocket.cpp
Normal file
27
reference/WebSocket/WebSocket.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "Core/Core.h"
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
// Open demo.html in browser, run this app, push the button...
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
StdLogSetup(LOG_COUT|LOG_FILE);
|
||||
|
||||
TcpSocket server;
|
||||
if(!server.Listen(8888)) {
|
||||
LOG("Failed to start listening on 8888..");
|
||||
return;
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
WebSocket ws;
|
||||
if(ws.WebAccept(server)) {
|
||||
LOG("Accepted connection");
|
||||
LOG(ws.Recieve());
|
||||
ws.SendText("Hello browser!");
|
||||
}
|
||||
if(ws.IsError())
|
||||
LOG("ERROR: " << ws.GetErrorDesc());
|
||||
}
|
||||
}
|
||||
10
reference/WebSocket/WebSocket.upp
Normal file
10
reference/WebSocket/WebSocket.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
WebSocket.cpp,
|
||||
demo.html;
|
||||
|
||||
mainconfig
|
||||
"" = "SSE2";
|
||||
|
||||
29
reference/WebSocket/demo.html
Normal file
29
reference/WebSocket/demo.html
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<button onclick="webs()">Test WebSocket</button>
|
||||
<script>
|
||||
|
||||
function webs() {
|
||||
if("WebSocket" in window) {
|
||||
var ws = new WebSocket("ws://localhost:8888");
|
||||
ws.onopen = function(){
|
||||
ws.send("Hello server!");
|
||||
};
|
||||
ws.onmessage = function(evt){
|
||||
alert(evt.data);
|
||||
};
|
||||
ws.onclose = function(ev) {
|
||||
};
|
||||
ws.onerror = function(ev){
|
||||
alert("Connection error: " + ev.reason);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
4
reference/WebSocket/init
Normal file
4
reference/WebSocket/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _WebSocket_icpp_init_stub
|
||||
#define _WebSocket_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#endif
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
description "Creating and parsing XML files";
|
||||
description "Creating and parsing XML files\377";
|
||||
|
||||
uses
|
||||
Core;
|
||||
|
|
|
|||
4
reference/XML/init
Normal file
4
reference/XML/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _XML_icpp_init_stub
|
||||
#define _XML_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue