91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

winsock 簡單的通信

發布時間:2020-07-10 19:38:06 來源:網絡 閱讀:621 作者:fengyuzaitu 欄目:系統運維

頭文件

#include <WinSock2.h>

#include <string>

#include <WS2tcpip.h>

#include <IPHlpApi.h>

#include <stdio.h>

#pragma comment(lib, "WS2_32.lib")


源代碼

// 初始化 Winsock

WSADATA wsaData;

int iResult;

iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);

if (iResult != 0) {

printf("WSAStartup failed: %d\n", iResult);

return NULL;

}


// 獲取連接屬性

struct addrinfo * result = NULL, *ptr = NULL, hints;

ZeroMemory(&hints, sizeof(hints));

hints.ai_family = AF_INET;

hints.ai_socktype = SOCK_STREAM;

hints.ai_protocol = IPPROTO_TCP;


iResult = getaddrinfo("192.168.0.18", "7002", &hints, &result);

//iResult = getaddrinfo("192.168.37.187", "7002", &hints, &result);

if (iResult != 0) {

printf("getaddrinfo failed: %d\n", iResult);

WSACleanup();

return NULL;

}


// 創建 Socket 對象

ptr = result;

SOCKET ConnectSocket = INVALID_SOCKET;

ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);

if (ConnectSocket == INVALID_SOCKET) {

printf("Error at socket(): %ld\n", WSAGetLastError());

freeaddrinfo(result);

WSACleanup();

return NULL;

}


// 鏈接

iResult = connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);

if (iResult == SOCKET_ERROR) {

printf("Error at socket(): %ld\n", WSAGetLastError());

closesocket(ConnectSocket);

ConnectSocket = INVALID_SOCKET;

}


int nSendBuf = 32 * 1000;//設置為32K

setsockopt(ConnectSocket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&nSendBuf, sizeof(int));

// Should really try the next address returned by getaddrinfo

// if the connect call failed

// But for this simple example we just free the resources

// returned by getaddrinfo and print an arror message

//freeaddrinfo(result);


if (ConnectSocket == INVALID_SOCKET) {

printf("Unable to connect to server!\n");

WSACleanup();

return NULL;

}


send(ConnectSocket, strSendContext.c_str(), strSendContext.length(), 0);


char szbuffer[1024] = { 0 };

recv(ConnectSocket, szbuffer, 1024, 0);

::closesocket(ConnectSocket);


說明

    當前內嵌代碼進行自動化測試


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

临猗县| 阿克陶县| 中牟县| 乐山市| 绥德县| 中卫市| 沙田区| 华蓥市| 辰溪县| 章丘市| 静海县| 昂仁县| 余庆县| 永城市| 和硕县| 沾化县| 隆昌县| 临漳县| 兰溪市| 饶平县| 宕昌县| 台南市| 嘉善县| 莆田市| 佛山市| 安顺市| 英山县| 宜城市| 松原市| 南康市| 杭州市| 会昌县| 东辽县| 呼图壁县| 马鞍山市| 吉水县| 台北市| 合山市| 房产| 浑源县| 贺州市|