仅当本人的学习笔记
首先是服务端的代码,一开始把文件名写死了,每次运行传输的文件都被覆盖,还以为哪里出错了,后来修改为自动创建的规律命名即可
server.cpp
#include <stdio.h>
#include <Winsock2.h>
#pragma comment(lib, "ws2_32.lib")
#include <iostream>
using namespace std;
int main()
{
WORD sockVersion = MAKEWORD(2, 2);
WSADATA wsaData;
if (WSAStartup(sockVersion, &wsaData) != 0)
{
cout << "error" << WSAGetLastError() << endl;
return 0;
}
SOCKET slisten = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (slisten == INVALID_SOCKET)
{
cout << "socket error!" << endl;
return 0;
}
sockaddr_in sin;
sin.sin_family = AF_INET;
sin.sin_port = htons(888);
sin.sin_addr.S_un.S_addr = INADDR_ANY;
if (bind(slisten, (sockaddr*)&sin, sizeof(sin)) == SOCKET_ERROR)
{
cout << "bind error!" << endl;
}
if (listen(sl