资源简介
该项目实现了在linux环境下的文件传输功能,能够将客户端的文件上传给服务器,同时能够将服务器的文件下载到客户端,可以在客户端查看更改双方路径及目录,并且支持多任务。在项目中应用了TCP网络编程,文件IO,多任务编程,进程间通信等相关知识,熟练综合运用了linux应用层相关知识。

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include “client_process.h“
int handle_server_ack(sockfd)
{
int ret;
uint32_t body_len;
uint32_t total_len;
msg_head_ctrl_t *msg;
ret = recv( sockfd &body_len sizeof(body_len) MSG_PEEK);
if ( ret<=0 ){
printf(“connectionn lost ... \n“);
exit(-1);
}
body_len = ntohl(body_len);
total_len = body_len + sizeof(msg_head_ctrl_t);
msg = malloc( total_len + 1 );
if ( NULL == msg ){
perror(“out of memeory\n“);
return ;
}
memset( msg 0 total_len + 1);
ret = recv( sockfd msg total_len MSG_WAITALL);
if ( ret<=0 ){
printf(“connectionn lost ... \n“);
exit(-1);
}
msg->body_len = ntohl(msg->body_len);
msg->command = ntohl(msg->command);
if ( (COMMAND_LS==msg->command) || (COMMAND_PWD==msg->command) ){
printf(“\n%s\n“msg->msg_body);
}
else if ( COMMAND_GET == msg->command ){
save_file_to_disk(msg->msg_body);
}
free(msg);
}
int send_command_to_server( int sockfd char *user_input command_type_t type)
{
ssize_t ret;
msg_head_ctrl_t *msg;
int body_len;
int total_len;
body_len = strlen(user_input);
total_len = body_len + sizeof(msg_head_ctrl_t);
msg = malloc(total_len);
if ( NULL == msg ){
printf(“out of memeory!\n“);
return FAILED;
}
msg->command = htonl(type);
msg->body_len = htonl(body_len);
memcpy(msg->msg_body user_input body_len);
ret = send(sockfd msg total_len 0);
if ( ret < total_len ){
printf(“connection lost ...\n“);
free(msg);
return SOCK_ERROR;
}
free(msg);
return SUCCESSFUL;
}
int get_file_from_server(int sockfd char *user_input command_type_t type)
{
int ret;
int fd=-1;
uint32_t len;
fd_set fs_client;
struct timeval timeout;
msg_head_ctrl_t *msg;
ret = send_command_to_server(sockfd user_input type);
if ( ret != SUCCESSFUL){
return ret;
}
msg = malloc(sizeof(msg_head_ctrl_t) + MAX_READ_BYTES + 1);
if ( NULL == msg ){
printf(“out of memory!\n“);
return FAILED;
}
while(true){
FD_ZERO(&fs_client);
FD_SET( sockfd &fs_client);
timeout.tv_sec = DEFAULT_CLIENT_TIME_OUT;
timeout.tv_usec = 0;
ret = select(sockfd+1 &fs_client NULL NULL NULL);
if ( 0 == ret ){
//time out
printf(“time out....\n“);
ret = SOCK_ERROR;
break;
}
if ( -1 == ret ){
continue;
}
memset(msg 0 sizeof(msg_head_ctrl_t) + MAX_READ_BYTES + 1);
ret = recv(sockfd &len sizeof(msg->body_len) MSG_PEEK);
if (ret <= 0){
printf(“sock error!\n“);
ret = SOCK_ERROR;
goto Exit;
}
len = ntohl(len);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2010-01-23 11:08 tcp\
文件 6764 2010-01-07 19:34 tcp\client_process.c
文件 355 2010-01-07 19:34 tcp\client_process.h
文件 1843 2010-01-07 19:34 tcp\common.c
文件 1401 2010-01-07 19:34 tcp\common.h
文件 1279 2010-01-07 19:34 tcp\ftpclient.c
文件 1769 2010-01-07 19:34 tcp\ftpserver.c
文件 340 2010-01-07 19:34 tcp\Makefile
文件 5825 2010-01-07 19:34 tcp\serv_client.c
文件 157 2010-01-07 19:34 tcp\serv_client.h
- 上一篇:35GHzVCO研制
- 下一篇:地铁自动售票机计算当前站和目的站的站数
相关资源
- linux系统下的内存测试工具
- GNU/Linux系统开发者需要从桌面突破
- the_definitive_guide_to_linux_network_programm
- linux-shell脚本命令:grep命令简介
- Learning Linux Binary Analysis
- 蓝牙源代码应用于LINUX
- Borland Socket Server Fix2.0 D7
- Borland Socket Server程序 包含D6和D7源码
- Micrium.RTOS.1.0.0.pack
- uboot到linux logo显示不间断 补丁
- ISE_14.7_license.lic
- stm32f103c8t6 4 oled.rar
- mpu6050+hmc5883L.rar
- UNIX/LINUX编程实践教程的源码
- 嵌入式图形界面MiniGUI的示例程序9例
- Linux任务管理器
- linux应用层的华容道游戏源代码
- 通信软件的具体实例──基于Socket的
- 用Socket编程实现FTP
- websocket实现一对一聊天
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- ARM嵌入式项目实战
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- 代码客:G-TcpServer(IOCP) 1.0 正式版及
评论
共有 条评论