Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Example websocket SSL
Example websocket SSL [message #49888] Tue, 29 May 2018 16:18 Go to next message
lovmy is currently offline  lovmy
Messages: 34
Registered: November 2015
Member

Hello,

do you have a example of code for websocket server with SSL (wss://) ?

Thank you !
Re: Example websocket SSL [message #51792 is a reply to message #49888] Fri, 31 May 2019 05:53 Go to previous message
kasome is currently offline  kasome
Messages: 78
Registered: July 2008
Location: Taiwan
Member
Hi, lovmy

The following example should work.

#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 (;;) {
		TcpSocket socket;
		WebSocket ws;
		if (socket.Accept(server)) {
			LOG("Connection accepted");
			socket.SSLCertificate(LoadFile(GetDataFile("server.crt")),LoadFile(GetDataFile("server.key")),false);
			if (!socket.StartSSL()) {
				LOG("Failed to start SSL: " << socket.GetErrorDesc());
				continue;
			}
			while (socket.SSLHandshake());
			if (socket.IsError()) {
				LOG("SSL handshake failed: " << socket.GetErrorDesc());
				continue;
			}
			LOG("SSL established");
			if (ws.WebAccept(socket)) {
				LOG("Accepted connection");
				LOG(ws.Recieve());
				ws.SendText("Hello browser!");
			}
		}
		if (ws.IsError())
			LOG("ERROR: " << ws.GetErrorDesc());
	}
}
Previous Topic: Clang / lld
Next Topic: Technology lab vs External resources
Goto Forum:
  


Current Time: Wed Jun 19 13:22:43 CEST 2019

Total time taken to generate the page: 0.01188 seconds