GithubHelp home page GithubHelp logo

jeremyhahn / cwebsocket Goto Github PK

View Code? Open in Web Editor NEW
51.0 51.0 28.0 1.32 MB

High performance websocket client/server in ANSI C

License: MIT License

Shell 0.03% C 97.12% Makefile 1.14% M4 1.70%
ansi c multi-threading websocket-client websocket-library websockets

cwebsocket's People

Contributors

jeremyhahn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cwebsocket's Issues

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?

cwebsocket_write_data fails to write over 65535 bytes and htonl64 fails.

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) }

can't build by c++ compiler

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

ifdef __cplusplus

extern "C" {

endif

// function definitions

ifdef __cplusplus

}

endif

and add ifndef in common.h

ifndef __cplusplus

typedef enum {
TRUE,
FALSE
} bool;

endif

doesn't work cwebsocket_write_data over 125 bytes payload

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];
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.