extension-websocket
extension-websocket copied to clipboard
Websocket server implementation.
Added non secure websocket server implementation.
@britzl thank you for testing the code. I will address the issues once I get some free time.
@JCash the http_server.cpp file is not the same from dmSDK, I had to change it heavily to make it work.
Hi. Anything blocking this from merge?
I am start work on new game and need websocket server for defold.
Also this is not worked for me in windows.
/native/websocket/src/wslay/wslay_frame.c
Line 79: use of undeclared identifier 'htons'
79 | uint16_t len = htons(iocb->payload_length);
| ^
I tried to add "#include <Winsock2.h>" but it not worked( /native/websocket/src/websocket.cpp Line 27: 'Winsock2.h' file not found 27 | #include <Winsock2.h> | ^~~~~~~~~~~~
# C++ symbol in your extension
name: "Websocket"
platforms:
common:
context:
flags: ["-std=c++11"]
includes: ["upload/websocket/include/wslay"]
defines: ["HAVE_CONFIG_H"]
x86_64-win32:
context:
libs: ["Ws2_32.lib"]
x86-win32:
context:
libs: ["Ws2_32.lib"]
Hi. Anything blocking this from merge?
Yes, the issues raised during the review have not been adressed.
@d954mas Since we build on Linux, the path casing is extra important. It's not actually called Winsock2.h, it's called WinSock2.h.
@d954mas Since we build on Linux, the path casing is extra important. It's not actually called Winsock2.h, it's called WinSock2.h.
Thanks for help. Now it build on windows.
Also this not build for html5 /native/websocket/src/wslay/wslay_frame.c Line 84: use of undeclared identifier 'htons' uint16_t len = htons(iocb->payload_length); ^
Is server worked in web? If not server should be removed from html?
I am making prototype for new game with websocket server in defold. I will be write here some problems that i find.
handshake not worked when i try to connect from web build to windows websocket server.
problem with header validation. Server except for "connection_header" "Upgrade" get "keep-alive, Upgrade"
// Helper function to check if a specified token is present in a header value
static bool HasToken(const char* headerValue, const char* tokenToFind) {
// Create a mutable copy of the headerValue
char* headerValueCopy = strdup(headerValue);
if (!headerValueCopy) {
dmLogError("Can't make str copy for HasToken");
return false; // Failed to allocate memory for the copy
}
char* last; // State pointer for dmStrTok
dmLogInfo("has token:%s", headerValueCopy);
char* token = dmStrTok(headerValueCopy, ", ", &last); // Get the first token
while (token != NULL) {
dmLogInfo("check token:%s", token);
if (dmStrCaseCmp(token, tokenToFind) == 0) {
free(headerValueCopy); // Clean up the allocated memory
return true; // Found the specified token
}
token = dmStrTok(NULL, ", ", &last); // Get the next token
}
free(headerValueCopy); // Clean up the allocated memory
return false; // Specified token not found
}
bool connection = connection_header && dmStrCaseCmp(connection_header->m_Value, "Upgrade") == 0;
bool upgrade = upgrade_header && dmStrCaseCmp(upgrade_header->m_Value, "websocket") == 0;
bool connection = connection_header && HasToken(connection_header->m_Value, "Upgrade");
bool upgrade = upgrade_header && HasToken(upgrade_header->m_Value, "websocket");
Not worked in linux
ERROR: native/websocket/src/wslay/wslay_frame.c:93: 'use of undeclared identifier 'htons'
93 | uint16_t len = htons(iocb->payload_length);'
ERROR: native/websocket/src/wslay/wslay_frame.c:93: 'use of undeclared identifier 'htons'
93 | uint16_t len = htons(iocb->payload_length);'
ERROR: native/websocket/src/wslay/wslay_frame.c:93: 'use of undeclared identifier 'htons'
93 | uint16_t len = htons(iocb->payload_length);'
Need add
#ifdef DM_PLATFORM_LINUX
#include <arpa/inet.h> // ntohl and htons
#endif