2 Star 0 Fork 0

litequark/echo_core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cli_core.h 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
litequark 提交于 30天前 . docs
//
// Created by zkm on 2025/5/20.
#ifndef CLI_CORE_H
#define CLI_CORE_H
#include <threads.h>
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
#include <winsock2.h>
#include <ws2tcpip.h>
typedef struct Server
{
SOCKET sock;
} SERVER;
typedef struct CallbackFn_Params
{
SOCKET sock;
int (*callback)(const char*, int len);
} CALLBACK_FN_PARAMS;
/**
* Initializes locale and Windows socket.
* MUST be called first.
*
* Exception: WSA network error.
* @return 0: success; WSA error code: failure.
*/
int cli_core_init();
/**
* Cleans up client.
* MUST be called prior to exiting.
*
* Exception: WSA network error.
* @return 0: success; WSA error code: failure.
*/
int cli_core_cleanup();
/**
* Initialize a SERVER instance.
* The returned SERVER instance must be freed by cli_core_logout.
* @param ip IPv4 address string to the server.
* @param port Port of the server.
* @param callback Function to be called when new msg arrives.
* @param wsa_error Pointer to an integer, to store WSA error code, or 0 if there are no WSA errors.
* @return Pointer to a SERVER instance: success; NULL: failure.
*/
SERVER* cli_core_login(const char* ip, int port, int (*callback)(const char*, int len), int* wsa_error);
/**
* Sends a message to the LAN.
* @param server Pointer to a SERVER instance.
* @param msg Message to be sent, in string.
* @param len Length (bytes) of the message string.
* @return 0: success; WSA error code: WSA failure; -1: internal error.
*/
int cli_core_send(SERVER *server, const char *msg, int len);
/**
* Disconnect client from server.
* The SERVER instance will be freed and set to NULL.
* @param server Pointer to a SERVER instance that has been initialized by cli_core_login.
* @return 0: success, -1: internal error.
*/
int cli_core_logout(SERVER *server);
#endif //CLI_CORE_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/litequark/echo_core.git
git@gitee.com:litequark/echo_core.git
litequark
echo_core
echo_core
main

搜索帮助