U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ MT-multithreading and servers » Websocket issue
Websocket issue [message #61956] Tue, 24 March 2026 12:16 Go to next message
przem_kaz is currently offline  przem_kaz
Messages: 10
Registered: April 2010
Location: Poland
Promising Member
Hi, upp community
I don't know if it's just my lack of experience, but I'm planning to build an app to communicate with a device that uses WebSocket to send events.

During testing, I noticed that my test app isn't establishing a connection correctly, even though the same connection works fine when using tools like Postman or Insomnia.
So I tested the connection with the most popular WebSocket test server: wss://echo.websocket.org.
And here, too, my app throws an error.
Code below.
#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	StdLogSetup(LOG_COUT|LOG_FILE);
	
	WebSocket::Trace();

		WebSocket ws;
		ws.Trace();
		LOG(GetSysTime());
		LOG(ws.GetHeaders());
		//ws.NonBlocking();		
		ws.Connect("wss://echo.websocket.org");
		if(ws.IsError()) {
			LOG("Failed to connect");
			LOG(ws.GetError());
			LOG(ws.GetErrorDesc());
			return;
		}
		Sleep(1000);
		LOG(GetSysTime());
		ws.SendText("010203");
		Sleep(1000);
		LOG("Response: ");
		LOG(ws.Receive());
		
		ws.Close();

}
Below is the log output:
03/24/2026 12:11:20
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: cs,en-US;q=0.7,en;q=0.3
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket

WS CLIENT DNS resolved
WS CLIENT Connect issued
WS CLIENT Blocking SSL handshake finished
WS CLIENT Sending connection request
WS CLIENT ERROR: Socket has been closed unexpectedly
Failed to connect
socket(668) / SSL handshake: SSL_ERROR_SSL; error:0A000126:SSL routines::unexpected eof while reading
socket(668) / SSL handshake: SSL_ERROR_SSL; error:0A000126:SSL routines::unexpected eof while reading

Can someone check if the SecureWebSockets implementation in UPP is working properly?

Thanks in advance for your help and advice

Best regards
Przemek

[Updated on: Tue, 24 March 2026 12:16]

Report message to a moderator

Re: Websocket issue [message #61957 is a reply to message #61956] Wed, 25 March 2026 08:04 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1265
Registered: August 2007
Senior Contributor
Hello Przemek,

Yes, I can confirm that WebSocket with SSL is broken for some setups, including your example, on both linux and Windows.
I'll investigate it further.

Best regards,
Oblivion


[Updated on: Wed, 25 March 2026 08:04]

Report message to a moderator

Re: Websocket issue [message #61958 is a reply to message #61957] Wed, 25 March 2026 08:41 Go to previous messageGo to next message
przem_kaz is currently offline  przem_kaz
Messages: 10
Registered: April 2010
Location: Poland
Promising Member
Hi Oblivion,

Thanks for the quick reply.
I'm sure you'll be able to fix this issue quickly.  

BR
Przemek
Re: Websocket issue [message #61959 is a reply to message #61958] Thu, 26 March 2026 17:18 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1265
Registered: August 2007
Senior Contributor
Ok, I fixed it, it works -here- with your example too. SSL connection was missing SNI.
However before the official patch, you can simply replace the connect method:

bool WebSocket::Connect(const String& uri_, const String& host_, bool ssl_, int port)
{
	Clear();
	
	client = true;
	redirect = 0;
	
	uri = uri_;
	host = host_;
	ssl = ssl_;
	
	if(ssl && !IsNull(host))
		socket->SSLServerNameIndication(host);

	if(socket->IsBlocking()) {
		if(!addrinfo.Execute(host, port)) {
			Error("Not found");
			return false;
		}
		LLOG("DNS resolved");
		StartConnect();
		while(opcode != READING_FRAME_HEADER) {
			Do0();
			if(IsError())
				return false;
		}
	}
	else {
		opcode = DNS;
		addrinfo.Start(host, port);
	}
	return true;
}

Best regards,
Oblivion


Re: Websocket issue [message #61960 is a reply to message #61959] Sat, 28 March 2026 11:31 Go to previous messageGo to next message
przem_kaz is currently offline  przem_kaz
Messages: 10
Registered: April 2010
Location: Poland
Promising Member
Hi Oblivion,

Thanks for finding a solution to this problem. Adding the code:
if(ssl && !IsNull(host))
    socket->SSLServerNameIndication(host);
solves the problem both with the test server “wss://echo.websocket.org” and when communicating directly with my device.

Now I’m going to play around with testing a secure WebSocket server, because I need both in my project.

BR
Przemek
Re: Websocket issue [message #61961 is a reply to message #61960] Sat, 28 March 2026 11:49 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1265
Registered: August 2007
Senior Contributor
Hi Przemek,

Note that, that's a temporary solution. Actual fix is here. That adds a method to set SNI information. The workaround you are using wont work with IP numbers or when name differs.

Best regards,
Oblivion


Re: Websocket issue [message #61962 is a reply to message #61961] Mon, 30 March 2026 16:43 Go to previous message
przem_kaz is currently offline  przem_kaz
Messages: 10
Registered: April 2010
Location: Poland
Promising Member
Hi Oblivion,
Thanks for this PR and the additional comment. I’ll wait patiently for Mirek to approve this PR.

There’s one more thing worth taking a look at. It seems that the Https reference example isn’t working properly either and displays that error message when client tries to establishing an SSL connection. Could you or Mirek check this out?

Connection accepted
SSL handshake failed: socket(632) / SSL handshake: Unknown error code.
===================================================== Waiting...
Connection accepted
SSL handshake failed: socket(652) / SSL handshake: Unknown error code.
BR
Przemek
Previous Topic: Can't use MT to capture console output
Next Topic: Https refarance example doesn't work
Goto Forum:
  


Current Time: Sun Apr 26 16:50:25 GMT+2 2026

Total time taken to generate the page: 0.00678 seconds