资源简介
在unbantu下用c语言实现的命令聊天室、可通过客户端上传和下载文件,还可实现单聊功能

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef struct{
int type;
int fd;
int fp;
int Mask;
char name[20];
char filename[30];
char buf[1000];
}Masg*Pm;
Pm P;
void *task(void *arg)
{
int s = *(int *)arg;
struct json_object *obj*type*data*name*filename*sure;
// write(P->fdbufstrlen(buf));
while(1)
{
char buf[1024]={};
char filedata[10]={};
int res =recv(sbufsizeof(buf)0);
if(res<=0)
break;
// strcpy(buf“{\“type\“:1}“);
obj = json_tokener_parse(buf);
type = json_object_object_get(obj“type“);
//printf(“type:%p\n“type);
data = json_object_object_get(obj“data“);
//printf(“data:%p\n“data);
name = json_object_object_get(obj“name“);
filename = json_object_object_get(obj“filename“);
//printf(“filename:%p\n“filename);
sure = json_object_object_get(obj“sure“);
//printf(“sure:%p\n“sure);
// printf(“buf **** =%s\n“buf);
// printf(“%s\n“json_object_to_json_string(obj));
if(json_object_get_int(type)==1)
{
// printf(“%s\n“json_object_to_json_string(obj));
printf(“群聊消息:%s\n“json_object_get_string(data));
}
else if(json_object_get_int(type)==2)
{
if(sure!=NULL)
{
if(strcmp(json_object_get_string(sure)“nofile“)==0)
{
printf(“没有该文件\n“);
continue;
}
if(strcmp(json_object_get_string(sure)“finish“)==0)
{
printf(“下载完成\n“);
close(P->fd);
continue;
}
}
if(filename!=NULL)
{
if(strcmp(json_object_get_string(filename)P->filename)==0) //返回文件名并创建
{
P->fd =open(P->filenameO_WRONLY|O_CREAT|O_TRUNC0666);
if(P->fd==-1)
{
perror(“sendfile“);
continue;
}
}
}
if(data!=NULL)
{
{
write(P->fdjson_object_get_string(data)strlen(json_object_get_string(data)));
}
}
}
else if(json_object_get_int(type)==3)
{
//printf(“%s\n“json_object_to_json_string(obj));
if(sure!=NULL)
{
if(strcmp(json_object_get_string(sure)“fail“)==0)
{
printf(“上传失败\n“);
continue;
}
if(strcmp(json_object_get_string(sure)“ready“)==0)
{
printf(“准备传输\n“);
}
}
json_object_object_del(obj“sure“);
json_object_object_del(obj“filename“);
while((res=read(P->fpfiledatasizeof(filedata)-1))>0)
{
//printf(“%s**************%ld\n“filedatasizeof(fi
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 18704 2018-10-29 19:31 TCPchat\cilent1\cilent1
文件 9560 2018-10-29 18:55 TCPchat\cilent1\cilent1.c
文件 290 2018-10-29 20:08 TCPchat\cilent1\file.txt
文件 206 2018-10-27 15:18 TCPchat\cilent1\test.txt
文件 290 2018-10-26 11:21 TCPchat\server\file.txt
文件 18864 2018-10-29 19:44 TCPchat\server\server
文件 8654 2018-10-29 19:43 TCPchat\server\server.c
文件 206 2018-10-29 20:09 TCPchat\server\test.txt
文件 21650 2018-10-30 18:29 TCPchat\设计文档.docx
目录 0 2018-10-29 20:08 TCPchat\cilent1
目录 0 2018-10-29 20:09 TCPchat\server
目录 0 2018-10-30 18:29 TCPchat
----------- --------- ---------- ----- ----
78424 12
- 上一篇:VC++关于纹理特征提取的代码完整
- 下一篇:如何在keil中查看程序执行时间
相关资源
- 操作系统c语言模拟文件管理系统844
- C语言开发实战宝典
- C++中头文件与源文件的作用详解
- C语言代码高亮html输出工具
- 猜数字游戏 c语言代码
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 使用C语言编写的病房管理系统
- 通信过程中的RS编译码程序(c语言)
- 计算机二级C语言上机填空,改错,编
- 用回溯法解决八皇后问题C语言实现
- 简易教务管理系统c语言开发文档
- 操作系统课设 读写者问题 c语言实现
- 小波变换算法 c语言版
- C流程图生成器,用C语言代码 生成C语
- 3des加密算法C语言实现
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- 个人日常财务管理系统(C语言)
- c语言电子商务系统
- 小甲鱼C语言课件 源代码
- 将图片转换为C语言数组的程序
- C语言实现的一个内存泄漏检测程序
- DES加密算法C语言实现
- LINUX下命令行界面的C语言细胞游戏
- 用单片机控制蜂鸣器播放旋律程序(
- 学校超市选址问题(数据结构C语言版
- 电子时钟 有C语言程序,PROTEUS仿真图
- 尚观培训linux许巍老师关于c语言的课
评论
共有 条评论