reference: WebSocket

git-svn-id: svn://ultimatepp.org/upp/trunk@6708 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-12-31 18:12:37 +00:00
parent f65a99f7ed
commit 5ba2e29db2
7 changed files with 79 additions and 1 deletions

View file

@ -0,0 +1,4 @@
#ifndef _SplitterFrame_icpp_init_stub
#define _SplitterFrame_icpp_init_stub
#include "CtrlLib/init"
#endif

View 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());
}
}

View file

@ -0,0 +1,10 @@
uses
Core;
file
WebSocket.cpp,
demo.html;
mainconfig
"" = "SSE2";

View 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
View file

@ -0,0 +1,4 @@
#ifndef _WebSocket_icpp_init_stub
#define _WebSocket_icpp_init_stub
#include "Core/init"
#endif

View file

@ -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
View file

@ -0,0 +1,4 @@
#ifndef _XML_icpp_init_stub
#define _XML_icpp_init_stub
#include "Core/init"
#endif