Home » U++ Library support » U++ MT-multithreading and servers » Websocket issue
| Websocket issue [message #61956] |
Tue, 24 March 2026 12:16  |
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 #61959 is a reply to message #61958] |
Thu, 26 March 2026 17:18   |
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
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
|
|
|
|
|
|
|
|
| Re: Websocket issue [message #61962 is a reply to message #61961] |
Mon, 30 March 2026 16:43  |
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
|
|
|
|
Goto Forum:
Current Time: Sun Apr 26 16:50:25 GMT+2 2026
Total time taken to generate the page: 0.00678 seconds
|