static int websock_server_data(struct mg_connection *conn, int bits, char *data, size_t data_len, void *udata) { (void)bits; ck_assert_ptr_eq((void *)udata, (void *)7531); printf("Server: Got %u bytes from the client\n", (unsigned)data_len); if (data_len < 3 || 0 != memcmp(data, "bye", 3)) { /* Send websocket acknowledge message */ mg_lock_connection(conn); mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, websocket_acknowledge_msg, websocket_acknowledge_msg_len); mg_unlock_connection(conn); } else { /* Send websocket acknowledge message */ mg_lock_connection(conn); mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, websocket_goodbye_msg, websocket_goodbye_msg_len); mg_unlock_connection(conn); } return 1; /* return 1 to keep the connetion open */ }
static int websock_server_data(struct mg_connection *conn, int bits, char *data, size_t data_len, void *udata) { (void)bits; ck_assert_ptr_eq((void *)udata, (void *)7531); printf("Server: Got %u bytes from the client\n", (unsigned)data_len); if (data_len == 3 && !memcmp(data, "bye", 3)) { /* Send websocket goodbye message */ mg_lock_connection(conn); mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, websocket_goodbye_msg, websocket_goodbye_msg_len); mg_unlock_connection(conn); } else if (data_len == 5 && !memcmp(data, "data1", 5)) { mg_lock_connection(conn); mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, "ok1", 3); mg_unlock_connection(conn); } else if (data_len == 5 && !memcmp(data, "data2", 5)) { mg_lock_connection(conn); mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, "ok 2", 4); mg_unlock_connection(conn); } else if (data_len == 5 && !memcmp(data, "data3", 5)) { mg_lock_connection(conn); mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, "ok - 3", 6); mg_unlock_connection(conn); } else { #if defined(__MINGW32__) || defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunreachable-code" #endif #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" #endif ck_abort_msg("Got unexpected message from websocket client"); return 0; #ifdef __clang__ #pragma clang diagnostic pop #endif #if defined(__MINGW32__) || defined(__GNUC__) #pragma GCC diagnostic pop #endif } return 1; /* return 1 to keep the connetion open */ }
int websocket_server_data(struct mg_connection * conn, int bits, char *data, size_t data_len, void *_ignored) #endif { printf("Server: Got %u bytes from the client\n", data_len); if (data_len<3 || 0!=memcmp(data, "bye", 3)) { /* Send websocket acknowledge message */ mg_lock_connection(conn); mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, websocket_acknowledge_msg, websocket_acknowledge_msg_len); mg_unlock_connection(conn); } else { /* Send websocket acknowledge message */ mg_lock_connection(conn); mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, websocket_goodbye_msg, websocket_goodbye_msg_len); mg_unlock_connection(conn); } return 1; /* return 1 to keep the connetion open */ }
void websocket_server_ready(struct mg_connection * conn, void * _ignored) #endif { printf("Server: Websocket ready\n"); /* Send websocket welcome message */ mg_lock_connection(conn); mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, websocket_welcome_msg, websocket_welcome_msg_len); mg_unlock_connection(conn); }
static void websock_server_ready(struct mg_connection *conn, void *udata) { ck_assert_ptr_eq((void *)udata, (void *)7531); printf("Server: Websocket ready\n"); /* Send websocket welcome message */ mg_lock_connection(conn); mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, websocket_welcome_msg, websocket_welcome_msg_len); mg_unlock_connection(conn); printf("Server: Websocket ready X\n"); }