Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <winsock2.h>
- #include <iostream>
- #include <cJSON.h>
- #include <vector>
- #include <string>
- #include <sstream>
- #include <map>
- #include <sha256.h>
- #include <cJSON.h>
- #include <algorithm>
- #include <fstream>
- #pragma comment(lib,"ws2_32.lib")
- #pragma warning(disable:4996)
- using namespace std;
- SOCKET connect(char*, int);
- int main(int argc, char* argv[])
- {
- SOCKET sock = connect(argv[1],atoi(argv[2]));
- SOCKADDR clntAddr;
- int nSize = sizeof(SOCKADDR);
- SOCKET clntSock;
- char received_message[1000] = { 0 };
- while (1)
- {
- //fgets(received_message, 1000, fin);
- cJSON* json;
- clntSock = accept(sock, (SOCKADDR *)& clntAddr, &nSize);
- memset(received_message, 0, sizeof(received_message));
- recv(clntSock, received_message, 1000, 0);
- }
- closesocket(sock);
- closesocket(clntSock);
- WSACleanup();
- return 0;
- }
- SOCKET connect(char*ip,int port)
- {
- WSADATA wsaData;
- WSAStartup(MAKEWORD(2, 2), &wsaData);
- SOCKET sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
- //綁定套接字
- sockaddr_in sockAddr;
- memset(&sockAddr, 0, sizeof(sockAddr)); //每個字節都用0填充
- sockAddr.sin_family = PF_INET; //使用IPv4地址
- sockAddr.sin_addr.s_addr = inet_addr(ip); //具體的IP地址
- sockAddr.sin_port = htons(port); //端口
- bind(sock, (SOCKADDR *)& sockAddr, sizeof(SOCKADDR));
- listen(sock, 5);
- return sock;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement