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 » 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 Go to previous messageGo to previous message
jjacksonRIAB is currently online  jjacksonRIAB
Messages: 220
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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Thread::GetId() returning 0
Next Topic: Windows authenticated web page load
Goto Forum:
  


Current Time: Mon May 06 17:04:59 CEST 2024

Total time taken to generate the page: 0.01689 seconds