jeremyhahn / cwebsocket Goto Github PK
View Code? Open in Web Editor NEWHigh performance websocket client/server in ANSI C
License: MIT License
High performance websocket client/server in ANSI C
License: MIT License
Hello @jeremyhahn, first of all, thank you for the project. Good Stuff.
One of our developers did a quick fork and started playing with it. We added socketio support. We are happy to share it back.
Nevertheless, I was thinking about using this in an iOS app and, sadly, the LGPL license will not allow it.
Are you open to do an MIT/BSD license on this?
The frame headers are wrong for frames with payload length over 65535. The below line in cwebsocket_write_data adds 10 additional bytes to header length when it should be only 8.
uint32_t header_length = 6 + (payload_len > 125 ? 2 : 0) + (payload_len > 0xffff ? 8 : 0);
Changing this to the below solves it.
uint32_t header_length = 6 + (payload_len > 125 ? 2 : 0) + (payload_len > 0xffff ? 6 : 0);
In common.h
#define htonl64(p) {\
(char)(((p & ((uint64_t)0xff << 0)) >> 0) & 0xff), (char)(((p & ((uint64_t)0xff << 8)) >> 8) & 0xff), \
(char)(((p & ((uint64_t)0xff << 16)) >> 16) & 0xff), (char)(((p & ((uint64_t)0xff << 24)) >> 24) & 0xff), \
(char)(((p & ((uint64_t)0xff << 32)) >> 32) & 0xff), (char)(((p & ((uint64_t)0xff << 40)) >> 40) & 0xff), \
(char)(((p & ((uint64_t)0xff << 48)) >> 48) & 0xff), (char)(((p & ((uint64_t)0xff << 56)) >> 56) & 0xff) }
needs to be changed to
#define htonl64(p) {\
(char)(((p & ((uint64_t)0xff << 56)) >> 56) & 0xff), (char)(((p & ((uint64_t)0xff << 48)) >> 48) & 0xff), \
(char)(((p & ((uint64_t)0xff << 40)) >> 40) & 0xff), (char)(((p & ((uint64_t)0xff << 32)) >> 32) & 0xff), \
(char)(((p & ((uint64_t)0xff << 24)) >> 24) & 0xff), (char)(((p & ((uint64_t)0xff << 16)) >> 16) & 0xff), \
(char)(((p & ((uint64_t)0xff << 8)) >> 8) & 0xff), (char)(((p & ((uint64_t)0xff << 0)) >> 0) & 0xff) }
I tried to build some c++ code with cwebsocket but it failed.
I success to build when I add codes below in each header files
extern "C" {
// function definitions
}
and add ifndef in common.h
typedef enum {
TRUE,
FALSE
} bool;
cwebsocket_write_data doesn't work over 125 bytes payload message.
so I fix cwebsocket_write_data code and success to send 225 bytes text message.
[code]
// add opcode parameter
ssize_t cwebsocket_write_data(cwebsocket_client *websocket, const char *data, int len, opcode code) {
// change header_length code
uint32_t masking_length = 4;
uint32_t header_length = ((len <= 125) ? 2 : (len <= 65535 ? 4 : 10)) + masking_length;
// set opcode to header
header[0] = code | 0x80;
// change code for header[1] and remove increase header_length code
if(payload_len <= 125) {
header[1] = payload_len | 0x80;
header[2] = masking_key[0];
header[3] = masking_key[1];
header[4] = masking_key[2];
header[5] = masking_key[3];
}
else if(payload_len <= 65535) {
header[1] = 126 | 0x80;
header[2] = (payload_len >> 8) & 0xff;
header[3] = (payload_len >> 0) & 0xff;
header[4] = masking_key[0];
header[5] = masking_key[1];
header[6] = masking_key[2];
header[7] = masking_key[3];
}
else {
header[1] = 127 | 0x80;
header[2] = (payload_len >> 56) & 0xff;
header[3] = (payload_len >> 48) & 0xff;
header[4] = (payload_len >> 40) & 0xff;
header[5] = (payload_len >> 32) & 0xff;
header[6] = (payload_len >> 24) & 0xff;
header[7] = (payload_len >> 16) & 0xff;
header[8] = (payload_len >> 8) & 0xff;
header[9] = (payload_len >> 0) & 0xff;
header[10] = masking_key[0];
header[11] = masking_key[1];
header[12] = masking_key[2];
header[13] = masking_key[3];
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.