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 #49892 is a reply to message #49885] |
Thu, 31 May 2018 07:05   |
jjacksonRIAB
Messages: 227 Registered: June 2011
|
Experienced Member |
|
|
OK, so it successfully upgrades if I use
ws.Connect("https://gateway.discord.gg", "gateway.discord.gg", true, 443);
instead of
ws.Connect("wss://gateway.discord.gg")
The browser plugin I used appears to automatically be converting all WSS GET requests from wss:// to https:// while U++ does not. I don't see where the standards say this conversion is a conformant behavior but it's happening anyway. What would be the fix in U++ source? I could change it to:
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);
String uri = url;
if(port == 443) {
uri.Replace("wss://", "https://");
}
else if(port == 80) {
uri.Replace("ws://", "http://");
}
return Connect(uri, host, ssl, port);
}
But I don't know if this is the "correct" conformant behavior or if the fix belongs deeper in the U++ source. I'm not a network protocol guy.
[Updated on: Thu, 31 May 2018 11:53] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat May 10 00:44:14 CEST 2025
Total time taken to generate the page: 0.03122 seconds
|