发送端:
/**************************************
客户端
**************************************/
#include <stdio.h>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h> /* superset of previous */
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int sockfd;
//./main 192.168.5.2 filename
//获取文件的大小
int get_file_size(char *filename)
{
int fd = open(filename,O_RDWR);
if(fd < 0)
{
perror("open fail:");
exit(0);
}
//把文件光标偏移到末尾获取文件的大小
int size = lseek(fd,0,SEEK_END);
close(fd);
return size;
}
int main(int argc, char **argv)
{
if(argc != 3)
{
perror("input IP and filename:");
return -1;
}
//1.创建网络通信对象
sockfd = socket(AF_INET, SOCK_STREAM , 0);
if (sockfd == -1)
{