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 #50188 is a reply to message #49892] Mon, 20 August 2018 09:24 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13975
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);
}
 
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 14:46:39 CEST 2024

Total time taken to generate the page: 0.01799 seconds