mirror of
https://github.com/taosdata/TDengine
synced 2026-05-24 10:09:01 +00:00
* test: add Makefile and test script for C ws examples * docs: add c ws new examples * docs: replace c ws examples with c ws new examples * fix: correct log file redirection syntax in c_ws scripts * style: format code * docs: update c/c++ zh doc * docs: add async demo and ws error code * docs: modify c/c++ zh doc * docs: rename asyncdemo.c to async_demo.c * docs: update c ws zh doc * docs: update c ws en docs * docs: fix typos and improve WebSocket connection documentation * docs: refactor code structure for improved readability and maintainability * docs: modify stmt en doc * fix: fix build doc errors * fix: fix return value * fix: delete taos_options * fix: fix return value * docs: update c/c++ connector docs
27 lines
672 B
C
27 lines
672 B
C
// to compile: gcc -o connect_example connect_example.c -ltaos
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "taos.h"
|
|
|
|
int main() {
|
|
const char *host = "localhost";
|
|
const char *user = "root";
|
|
const char *passwd = "taosdata";
|
|
const char *db = NULL;
|
|
uint16_t port = 6041;
|
|
|
|
int code = taos_options(TSDB_OPTION_DRIVER, "websocket");
|
|
if (code != 0) {
|
|
fprintf(stderr, "Failed to set driver option, code: %d\n", code);
|
|
return -1;
|
|
}
|
|
|
|
TAOS *taos = taos_connect(host, user, passwd, db, port);
|
|
fprintf(stdout, "Connected to %s:%hu successfully.\n", host, port);
|
|
|
|
/* put your code here for read and write */
|
|
|
|
taos_close(taos);
|
|
taos_cleanup();
|
|
}
|