服务端:
#include "winsock2.h"
#pragma comment(lib, "ws2_32.lib")
#include <iostream>
#include <thread>
using namespace std;
class server
{
public:
WSADATA wsaData;
SOCKET sockServer;
SOCKADDR_IN addrServer;
SOCKET sockClient;
SOCKADDR_IN addrClient;
server();
void send();
void recv();
};
server::server()
{
if (WSAStartup(MAKEWORD(2,2),&wsaData) != 0)
{
cout << "WSAStartup failed!" << endl;
return;
}
//创建套接字
sockServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(INVALID_SOCKET == sockServer)
{
cout << "socket failed!" << endl;
WSACleanu