1 Star 0 Fork 0

youquc/mycapp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
myclient.h 928 Bytes
一键复制 编辑 原始数据 按行查看 历史
easydots 提交于 2021-03-04 19:36 . save file to server ok
#ifndef __MYCLIENT_H__
#define __MYCLIENT_H__
#include<stdio.h>
#include<stdlib.h>
#include<winsock2.h>
#include<windows.h>
int myclient_send(char *addr, int port, char *sendData, char *retBuf) {
int ret = -2;
WORD sockVersion = MAKEWORD(2,2);
WSADATA data;
if(WSAStartup(sockVersion, &data) != 0) {
return -1;
}
SOCKET sclient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(sclient == INVALID_SOCKET) {
printf("socket error");
return -1;
}
struct sockaddr_in serAddr;
serAddr.sin_family = AF_INET;
serAddr.sin_port = htons(port);
serAddr.sin_addr.S_un.S_addr = inet_addr(addr);
if(connect(sclient, (struct sockaddr *)&serAddr,sizeof(serAddr)) == SOCKET_ERROR) {
printf("connect error");
return -1;
}
send(sclient, sendData, strlen(sendData), 0);
ret = recv(sclient, retBuf, 255, 0);
if(ret > 0) {
retBuf[ret] = 0x00;
}
closesocket(sclient);
WSACleanup();
return ret;
}
#endif
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/youquc/mycapp.git
git@gitee.com:youquc/mycapp.git
youquc
mycapp
mycapp
master

搜索帮助