#include
#include
#include
#pragma comment(lib “ws2_32.lib“)
/**
*连接服务器
*/
SOCKET connect_server(char *host int port);
void disconnect(SOCKET c);
void send_msg(SOCKET c char *msg);
void recv_msg(SOCKET c);
char* base64_encode(const char* data int data_len);
const char base[] = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=“;
SOCKET connect_server(char *host int port)
{
WSADATA wd;
int ret = 0;
SOCKET c;
SOCKADDR_IN saddr;
struct hostent *pHostent;
ret = WSAStartup(MAKEWORD(2 2) &wd);
if (ret != 0)
{
return 0;
}
if (HIBYTE(wd.wVersion) != 2 || LOBYTE(wd.wVersion) != 2)
{
printf(“Failed to initialize“);
WSACleanup();
return 1;
}
c = socket(AF_INET SOCK_STREAM 0);
pHostent = gethostbyname(host);
// printf(“%s“ inet_ntoa(*((struct in_addr*)pHostent->h_addr_list[0])));
saddr.sin_addr.S_un.S_addr = *((unsigned long*)pHostent->h_addr_
评论
共有 条评论