资源简介
这是一个运行于Linux环境下的基于服务器的文件共享程序,拥有网络连接,文件上传下载以及管理等功能!

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “Global.h“
using namespace std;
string GetHostIP();
int ConnectServer();
void UploadFile();
void DownloadFile();
void LookoverList();
void RefreshList();
int clientSock;
list gFileList;
list::iterator gIter;
char gMsgBuf[BUFSIZE];
int main()
{
while(1)
{
system(“clear“);
cout<<“\t\t------------------Client------------------\n“< cout<<“\n\t\tChoose the operation from the menu:“< cout<<“\t\t1.Upload files to server“< cout<<“\t\t2.Download files from server“< cout<<“\t\t3.Lookover list of files“< cout<<“\t\t0.Exit“< cout<<“\t\tPlease input your option:“;
int opt;
cin>>opt;
switch(opt)
{
case 1:
UploadFile();
break;
case 2:
DownloadFile();
break;
case 3:
LookoverList();
break;
case 0:
system(“clear“);
return 0;
default:
cout<<“\n\t\tinput illegal!“< continue;
}
}
return 0;
}
int ConnectServer()
{
sockaddr_in addr;
if((clientSock=socket(AF_INETSOCK_STREAM0))<0)
{
perror(“socket“);
exit(1);
}
bzero(&addrsizeof(addr));
addr.sin_family=AF_INET;
addr.sin_port=htons(PORT);
addr.sin_addr.s_addr=inet_addr(REMOTE_IP);
if(connect(clientSock(sockaddr*)&addrsizeof(addr))<0)
{
perror(“connect“);
exit(1);
}
return 0;
}
void UploadFile()
{
RefreshList();
ConnectServer();
bzero(gMsgBufsizeof(gMsgBuf));
FileItem file;
cout<<“\t\tPlease input the path of file:\n\t\t“;
string strPath;
cin>>strPath;
int pos=strPath.find_last_of(‘/‘);
strcpy(file.attrib.namestrPath.substr(pos+1).c_str());
strcpy(file.attrib.ipAddrGetHostIP().c_str());
FILE *fileStream;
if((fileStream=fopen(strPath.c_str()“r“))==NULL)
{
printf(“\n\t\tthe file was not opened!\n“);
close(clientSock);
return;
}
int len=fread(file.content1900fileStream);
file.attrib.size=len;
Message msg;
msg.msgType=UPLOADFILE;
memcpy(msg.date&filesizeof(FileItem));
memcpy(gMsgBuf&msgsizeof(msg));
if(send(clientSockgMsgBufBUFSIZE0)<0)
perror(“send“);
fclose(fileStream);
close(clientSock);
gFileList.push_back(file.attrib);
}
void DownloadFile()
{
RefreshList();
ConnectServer();
cout<<“\t\tPlease input the order of file you want to download:“;
int fileOrder;
cin>>fileOrder;
if(fileOrder>gFileList.size()||fileOrder<=0)
{
cout<<“\n\t\tInput illegal!“<
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1395 2012-06-30 17:02 Client代码\Global.h
文件 5806 2012-06-30 17:02 Client代码\main.cpp
文件 1461 2012-06-30 17:02 Server代码\Global.h
文件 14972 2012-06-30 17:02 Server代码\main.cpp
目录 0 2012-06-30 17:03 Client代码
目录 0 2012-06-30 17:03 Server代码
----------- --------- ---------- ----- ----
23634 6
- 上一篇:CAD展点小程序
- 下一篇:数据库系统课程设计——银行管理系统
相关资源
- 虚拟光驱deamon 适用于64位服务器的
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- 编写简单的RMI程序 多线程web 服务器
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- IOCP 类 简单的IOCP(IO完成端口)服务
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- CVI下的TCP服务器和客户端
- linux下用多进程同步方法解决生产者
- SOCKET 网络编程 计算机网络 作业 客户
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- 用Socket写的简易FTP服务器和客户端
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
- vc 编写的基于TCP协议的客户/服务器
评论
共有 条评论