Home » U++ Library support » U++ MT-multithreading and servers » [SOLVED] Discord bot 404 error using WebSocket, any ideas?
Re: Discord bot 404 error using WebSocket, any ideas? [message #50188 is a reply to message #49892] |
Mon, 20 August 2018 09:24   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
Thank you, specification seems to say the ws/wss should be replaced with http/https:
3. The "Request-URI" part of the request MUST match the /resource
name/ defined in Section 3 (a relative URI) or be an absolute
http/https URI that, when parsed, has a /resource name/, /host/,
and /port/ that match the corresponding ws/wss URI.
so the code in U++ was wrong (looks like the server the we are testing against ignores this...).
Fixed:
bool WebSocket::Connect(const String& url)
{
const char *u = url;
bool ssl = memcmp(u, "wss", 3) == 0;
const char *t = u;
while(*t && *t != '?')
if(*t++ == '/' && *t == '/') {
u = ++t;
break;
}
t = u;
while(*u && *u != ':' && *u != '/' && *u != '?')
u++;
String host = String(t, u);
int port = ssl ? 443 : 80;
if(*u == ':')
port = ScanInt(u + 1, &u);
return Connect(url.StartsWith("wss:") ? "https:" + url.Mid(4)
: url.StartsWith("ws:") ? "http:" + url.Mid(3) : url,
host, ssl, port);
}
|
|
|
Goto Forum:
Current Time: Sat May 10 01:10:06 CEST 2025
Total time taken to generate the page: 0.02513 seconds
|