资源简介
基于C语言的多人聊天室,C/S结构,可在在linux系统下运行,附有report和源码,使用mysql数据库,当有用户进入聊天室时,会通知所有人
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BUFFER_SIZE 1024
#define FILE_NAME_MAX_SIZE 1024
#define HELLO_WORLD_SERVER_PORT 6666
struct sockaddr_in clientaddr;
pid_t pid;
int clientfdsendbytesrecvbytes;
struct hostent *host;
char *buf*buf_r;
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *i;
char *userid;
char *userpwd;
char sql[1024];
char *Name;
ssize_t r_write(int fd void *buf size_t size) {
char *bufp;
size_t bytestowrite;
ssize_t byteswritten;
size_t totalbytes;
for (bufp = buf bytestowrite = size totalbytes = 0;
bytestowrite > 0;
bufp += byteswritten bytestowrite -= byteswritten) {
byteswritten = write(fd bufp bytestowrite);
if ((byteswritten) == -1 && (errno != EINTR))
return -1;
if (byteswritten == -1)
byteswritten = 0;
totalbytes += byteswritten;
}
return totalbytes;
}
sendfile(void *ppid_t id)
{
int client_socket = socket(AF_INETSOCK_STREAM0);
client_socket = *(int *)p;
char file_name[FILE_NAME_MAX_SIZE+1];
bzero(file_name FILE_NAME_MAX_SIZE+1);
printf(“Please Input File Name On Server:\t“);
scanf(“%s“ file_name);
char buffer[BUFFER_SIZE];
bzero(bufferBUFFER_SIZE);
strncpy(buffer file_name strlen(file_name)>BUFFER_SIZE?BUFFER_SIZE:strlen(file_name));
//鍚戞湇鍔″櫒鍙戦€乥uffer涓殑鏁版嵁
send(client_socketbufferBUFFER_SIZE0);
int fp = open(file_name (O_WRONLY|O_CREAT|O_EXCL)(S_IRUSR | S_IWUSR));
if( fp < 0 )
// FILE * fp = fopen(file_name“w“);
// if(NULL == fp )
{
printf(“File:\t%s Can Not Open To Write\n“ file_name);
exit(1);
}
//浠庢湇鍔″櫒鎺ユ敹鏁版嵁鍒癰uffer涓? bzero(bufferBUFFER_SIZE);
ssize_t length = 0;
length = recv(client_socketbufferBUFFER_SIZE0);
if(length < 0)
{
printf(“Recieve Data From Server Failed!\n“);
exit(1);
}
int write_length = r_write(fp bufferlength);
// int write_length = fwrite(buffersizeof(char)lengthfp);
if (write_length {
printf(“File:\t%s Write Failed\n“ file_name);
exit(1);
}
memset(buffer‘\0‘BUFFER_SIZE);
bzero(bufferBUFFER_SIZE);
printf(“Recieve File:\t %s From Server Finished\n“file_name);
close(fp);
// fclose(fp);
recv(client_socketbufferBUFFER_SIZE0);
// close(client_socket);
return 0;
}
void sigOut(int sigNum)
{
strcpy(bufName);
strcat(buf“ “);
memset(buf_r0100);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 226816 2009-11-04 22:57 project report.doc
文件 8289 2009-11-04 22:51 server5.c
文件 6465 2009-11-05 00:15 client5.c
----------- --------- ---------- ----- ----
241570 3
相关资源
- 操作系统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语言的课
川公网安备 51152502000135号
评论
共有 条评论