资源简介
基于TCP的C/S结构程序,能上传下载文件,在客户端显示进度,能随时终止上传下载,传输速度也还不错

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#define SERVER_PORT 7000 //侦听端口
#define BUF_SIZE 40960
char *down_path = “E:\\第二个作业\\TCP\\downfile\\“;
char down_name[][512] = {“11.rar““hh.exe““ll.exe““5.jpg“};
char up_name[][512] = {“vc.rar““xinjiang.ts““kuwo.exe““dvb.pdf““4.jpg“};
unsigned long get_file_lenth(const char* filename)
{
int file_lenth;
FILE *fp=fopen(filename“rb“);
if(fp==NULL)
{
printf(“ERROE:open file %s faile!\n“filename);
return 0;
}
fseek(fp0LSEEK_END);
file_lenth=ftell(fp);
fseek(fp0LSEEK_SET);
return file_lenth;
}
//文件上传
void client_put(const char filename[]SOCKET sockfd)
{
char buf_client_write[BUF_SIZE];
int write_bytesfile_block;
FILE *fp;
long int file_lenth;
long int lenth[10];//装文件长度数组
char filesize[256];
char ch;
int i=0;
//将buf_server_write中文件名发送至服务端
memset(buf_client_write0sizeof(buf_client_write));//将数组清空
strncpy(buf_client_writefilenamestrlen(filename));
if((write_bytes=send(sockfdbuf_client_writeBUF_SIZE0))==-1)
{
printf(“Server : I send filename fail \n“);
return;
}
printf(“filename success\n“);
file_lenth=get_file_lenth(filename);
lenth[0] = file_lenth/1024;//将字节数转换为KB
printf(“the file lenth is %d KB\n“(lenth[0]+1));
//发送文件大小
itoa(file_lenthfilesize10);
send(sockfdfilesize256+10);
//打开要发送的文件
fp = fopen(filename“rb+“);
if(fp == NULL)
{
MessageBox(NULL“文件为空“““MB_OK);
return ;
}
else
{
//清空发送缓冲区
memset(buf_client_write0sizeof(buf_client_write));
file_block=0;
while(file_lenth>0)
{
if(!kbhit())// 没有按键操作就传输数据
{
if((file_block=fread(buf_client_writesizeof(char)BUF_SIZEfp))<0)
{
printf(“read error\n“);
return;
}
file_lenth -= file_block;
if(send(sockfdbuf_client_writefile_block0)<0)
{
printf(“send error\n“);
return;
}
i++;
if(30 == i)
{
fprintf(stdout“ˉ“);
i=0;
}
memset(buf_client_write0sizeof(buf_client_write));
if(feof(fp))
break;
}
else
{
ch = getch();
if(ch != ‘p‘)
continue;
do
{
ch = getch(); // 接收第二次按键
}
while(ch != ‘p‘);
}
}
fclose(fp);
printf(“Client: I transmit finish !\n“);
}
}
//文件下载
void client_get(const char filename[]SOCKET sockfd)
{
char buf[BUF_SIZE]recv_buf[BUF_SIZE];
int write_bytesread_bytesfile_block;
FILE *fp1;
char filesize[256]ch;
long int filelen;
int i=0;
char full_name[512];
int time1time2;
fd_set fdsets;
int nTimeOut=0;
TIMEVAL tv;
int nNum;
tv.tv_sec = nTimeOut / 1000;
tv.tv_usec = nTimeOut % 1000;
nNum = select(0 &
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 119562 2014-03-26 21:38 TCP\client\4.jpg
文件 7290 2014-04-02 15:16 TCP\client\client.c
文件 4321 2014-03-21 21:20 TCP\client\client.dsp
文件 535 2014-03-21 19:47 TCP\client\client.dsw
文件 50176 2014-04-02 16:53 TCP\client\client.ncb
文件 53760 2014-04-02 16:53 TCP\client\client.opt
文件 246 2014-04-02 15:16 TCP\client\client.plg
文件 2057216 2014-03-26 20:35 TCP\client\Debug\client.bsc
文件 188474 2014-04-02 15:16 TCP\client\Debug\client.exe
文件 255472 2014-04-02 15:16 TCP\client\Debug\client.ilk
文件 30326 2014-04-02 15:16 TCP\client\Debug\client.obj
文件 2853176 2014-04-02 11:46 TCP\client\Debug\client.pch
文件 508928 2014-04-02 15:16 TCP\client\Debug\client.pdb
文件 0 2014-03-26 20:35 TCP\client\Debug\client.sbr
文件 66560 2014-04-02 16:47 TCP\client\Debug\vc60.idb
文件 69632 2014-04-02 15:16 TCP\client\Debug\vc60.pdb
文件 794160 2014-03-26 08:51 TCP\client\dvb.pdf
文件 119562 2012-04-07 12:26 TCP\server\4.jpg
文件 783156 2014-03-09 10:12 TCP\server\5.jpg
文件 2057216 2014-03-24 12:05 TCP\server\Debug\server.bsc
文件 167994 2014-04-02 11:52 TCP\server\Debug\server.exe
文件 213004 2014-04-02 11:52 TCP\server\Debug\server.ilk
文件 23026 2014-04-02 11:52 TCP\server\Debug\server.obj
文件 2856520 2014-04-02 11:52 TCP\server\Debug\server.pch
文件 484352 2014-04-02 11:52 TCP\server\Debug\server.pdb
文件 0 2014-03-24 12:05 TCP\server\Debug\server.sbr
文件 58368 2014-04-02 16:43 TCP\server\Debug\vc60.idb
文件 69632 2014-04-02 11:52 TCP\server\Debug\vc60.pdb
文件 199645 2009-03-21 09:49 TCP\server\Linux.mht
文件 6733 2014-04-02 11:52 TCP\server\server.c
............此处省略13个文件信息
- 上一篇:银行Logo银行列表银行名称银行编码.rar
- 下一篇:捷联惯导系统原理_陈哲
相关资源
- TCP通讯(接收.vi)
- 在LabVIEW 中利用TCPIP协议实现网络通信
- windows XP 系统关闭445端口方法
- 永久启动和禁用win10驱动签名验证脚本
- PcShutDownByTime.zip
- Windows 内存监控 日志
- 《Windows PowerShell 4.0 for .NET Developers》
- VC仿Windows记事本源代码
- 易语言高仿Windows记事本源码
- Trojan-Qt5-Windows-0.0.4.rar
- TCP IP通信labview程序
- Modbus协议官方文档中、英文全
- AE开发Windows最短路径分析
- Omron ETN21模块进行modbustcp通讯
-
Windows em
bedded Compact 2013 应用开发调 - 黑苹果硬件兼容检测和查询软件
- Uninstall_Cortana_WINCLIENT.CN.rar
- VMware65_SLP_DeLLSLIC2.1
- Windows异步套接字网络编程
- WINDOWS98启动盘镜像Win98.IMA
- 仿windows记事本
- windows7用的,非常漂亮的透明计时器
- Openssl给文件传输加密
- 组态王中S7-300TCP驱动
- 基于Apache Mina实现的TCP长连接和短连接
- windows下制作macOS安装U盘,绝对简单好
- tftp文件传输工具
- CVI下的TCP服务器和客户端
- 代码客:G-TcpServer(IOCP) 1.0 正式版及
- keil vcom windows 7 64bit 驱动
评论
共有 条评论