资源简介
linux聊天室 实现了 具名注册,具名/匿名登录,公聊,私聊
另课程设计报告也一并完成。
客户/服务器模式

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include“wrap.h“
#include“define.h“
#include“thread.h“
#include“welcome.h“
void *read_server(void *);
void welcome();
void welcome_regist(int );
int welcome_login();
void deal_user_info(char * char *);
void *deal_log_in(void *arg);
void welcome_chat();
/*********************************************************************
函数名:main()
函数功能:初始化聊天室信息,接受用户的选择
传入参数:无
传出参数:无
返回值:无
*********************************************************************/
int main(int argc char *argv[])
{
char ip[100];
if ( argc == 1 )
{
strcpy(ip “127.0.0.1“);
}
else if ( argc == 2 )
{
strcpy(ip argv[1]);
}
else
{
printf(“Usage : <%s ip>\n“ argv[0]);
exit(1);
}
char opt[20];
// int c;
int nread;
int sockfd;
int connfd;
struct sockaddr_in server;
sockfd = Socket(AF_INET SOCK_STREAM 0);
server.sin_family = AF_INET;
server.sin_port = htons(SERVER_PORT);
server.sin_addr.s_addr = inet_addr(ip);
connfd = connect(sockfd ( struct sockaddr *)(&server) sizeof(server));
if ( connfd < 0 )
{
perror(“connect error!“);
exit(1);
}
while (1)
{
welcome();
nread = read(1 opt 20);
if ( nread < 1 || nread > 20 )
{
printf(“请输入正确的长度\n“);
}
int c = atoi(opt);
switch ( c )
{
case 10:
// welcome_anonymous_regist(sockfd);
break;
case 11:
welcome_regist(sockfd);
break;
case 20:
welcome_anonymous_regist(sockfd);
welcome_anonymous_login(sockfd);
break;
case 21:
welcome_login(sockfd);
break;
case 88:
exit(0);
break;
default:
printf(“你输入的序号不正确,请重新输入\n“);
break;
}
}
return 0;
}
/************************************************************
函数名:deal_user_info()
函数说明:处理用户信息,将用户名和密码打包
传入参数:char类型的指针name
char类型的指针passwd
传出参数:无
返回值:无
************************************************************/
void deal_user_info(char *name char *passwd)
{
name[strlen(name)-1] = ‘\0‘;
strcat(name “:“);
strcat(namepasswd);
name[strlen(name)-1] = ‘\0‘;
}
/***********************************************************
文件名:client1.c
函数名:analyse_send_msg()
函数说明:该函数将从终端输入的消息解析出来,将解析后的结果存
放在send_buf中。
传入参数:Msg类型的指针send_buf.
char类型的指针msg.
传出参数:Msg类型的指针send_buf
返回值:1或0.
***********************************************************/
int analyse_send_msg(Msg *send_buf char *msg)
{
int counter = 0;//计算命令和消息之间的空格个数
int i = 0;//数组下标
msg[ strlen(msg)-1 ] = ‘\0‘;//将msg中的‘\n’转化为‘\0‘
if ( *msg == ‘/‘ )//如果是对某人说话
{
send_buf->option = TOSB;//设置option为TOSB
/*该循环判断用户输入的命令和消息之间是否有空格*/
while ( msg[i] != ‘\0‘ )
{
if ( msg[i] == ‘ ‘ )
{
counter++;
}
i++;
}
/*如果输入的命令和消息之间没有空格则返回错误*/
if ( counter == 0 )
{
return FAILURE;
}
msg = msg + 1;//使msg指向‘/’后面一个字符
strcpy(send_buf->message msg);
// printf(“
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-06-17 17:03 code\
文件 502720 2012-06-04 13:04 code\C 网络程序设计 课程设计.pptx
目录 0 2012-06-14 11:35 code\makefile_chatcode\
目录 0 2012-06-12 15:04 code\makefile_chatcode\client\
文件 4733 2012-06-11 15:37 code\makefile_chatcode\client\client1.c
文件 1315 2010-09-26 18:13 code\makefile_chatcode\client\client_msg.txt
文件 330 2012-06-08 17:07 code\makefile_chatcode\client\define.h
文件 319 2012-06-12 15:02 code\makefile_chatcode\client\Makefile
文件 3302 2010-09-26 18:13 code\makefile_chatcode\client\thread.c
文件 62 2010-09-26 18:13 code\makefile_chatcode\client\thread.h
文件 8814 2012-06-12 13:38 code\makefile_chatcode\client\welcome.c
文件 185 2012-06-08 16:00 code\makefile_chatcode\client\welcome.h
文件 2916 2010-09-26 18:13 code\makefile_chatcode\client\wrap.c
文件 673 2010-09-26 18:13 code\makefile_chatcode\client\wrap.h
文件 363 2012-06-17 17:02 code\makefile_chatcode\readme.txt
文件 311 2012-06-12 15:10 code\makefile_chatcode\readme.txt.bak
目录 0 2012-06-17 17:02 code\makefile_chatcode\server\
文件 2041 2012-06-10 22:21 code\makefile_chatcode\server\add_online_user.c
文件 481 2012-06-10 22:21 code\makefile_chatcode\server\add_online_user.h
文件 2436 2012-06-11 10:26 code\makefile_chatcode\server\add_online_user.o
文件 310 2012-06-10 22:21 code\makefile_chatcode\server\define.h
文件 358 2012-06-10 23:00 code\makefile_chatcode\server\Makefile
文件 359 2012-06-10 22:21 code\makefile_chatcode\server\Makefile~
文件 64 2012-06-10 22:21 code\makefile_chatcode\server\parse_message.c
文件 278 2012-06-10 22:21 code\makefile_chatcode\server\parse_message.h
文件 5317 2012-06-10 22:21 code\makefile_chatcode\server\read_reg_user.c
文件 412 2012-06-10 22:21 code\makefile_chatcode\server\read_reg_user.h
文件 2956 2012-06-11 10:26 code\makefile_chatcode\server\read_reg_user.o
文件 118 2012-06-12 13:42 code\makefile_chatcode\server\record.txt
文件 117 2012-06-12 11:06 code\makefile_chatcode\server\record.txt~
文件 22159 2012-06-11 10:26 code\makefile_chatcode\server\server
............此处省略10个文件信息
- 上一篇:mui 商城案例
- 下一篇:bootstrap-table插件相关的css和js文件
相关资源
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- 通信软件的具体实例──基于Socket的
- 用VC 编写的仿QQ聊天室程序源代码
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- 课程作业:模拟仓库管理系统
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- 一个简单实用个人日记管理系统
- 带时间温度显示的室内灯光控制系统
- 成绩管理系统(数据结构)
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- FIR低通滤波器 ccs运行环境
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
评论
共有 条评论