客户端将本地文件传输给服务端,服务端接收文件并保存,输出文件名和内容
客户端:
#include<stdio.h>
#include<string.h>
#include<Winsock2.h>
#pragma comment(lib,"ws2_32.lib")
int main()
{
WSAData wsaData;
int err=WSAStartup(WINSOCK_VERSION,&wsaData);
if(0!=err)
{
return -1;
}
SOCKET sock;
sock=socket(AF_INET,SOCK_DGRAM,0);
if(INVALID_SOCKET==sock)
{
printf("socket()Failed:%d\n",WSAGetLastError());
WSACleanup();
return -1;
}
char data[]="Hello World!";
char dest_ip[]="222.196.201.224"; //目的IP
unsigned short dest_port=20000;//目的端口
sockaddr_in RemoteAddr;
RemoteAddr.sin_family = AF_INET;
RemoteAddr.sin_port = htons(dest_port);
RemoteAddr.sin_addr.s_addr=inet_addr(dest_ip);
char path[100]={"0"};
while(1)