資源簡介
基于嵌入式linux的網(wǎng)絡(luò)聊天室的實現(xiàn),有詳細的軟件設(shè)計文檔,用戶手冊,及源碼
代碼片段和文件信息
/*?client.c?
?*
?*?data:07-02-07
?*
?*?version:1.3
?*?*/
#include“sec_group.h“
#include“client.h“
#include“client_online_list.h“
#include?“gui.h“
#include?“msg_list.h“
#include?“write_record.h“
#define?port?8001
char?TOWHO[20];
void?thread(int?sock_fd);
void?record_select(void);
/*------------------------------------*/
void?first_print_select(int?fd);
void?client_load_deal(int?sock_fd);
void?client_reg_deal(int?sock_fd);
void?client_command_to(char?*?bufchar?*?name);
void?client_command_quit(int?fd);
void?use_command_to_deal(char?*buf);
/*-----------------------------------------*/
/*?the?first?*//*?1^*/
/*?include?two?function?to?make?a?link?*/
int?main(int?argc?char?*argv[])
{
int?wild_sock_fd;
client_help(argcargv);
memset(TOWHO020);
wild_sock_fd?=??create_connect_server();
deal_connect(wild_sock_fd);
return?0;
}
/*-----------------------------------------*/
/*?the?two?*//*?2^*/
/*?create?the?connet?it?didn‘t?have?another?function*/
int?create_connect_server(void)
{
struct?sockaddr_in?pin;
int?sock_fd;
int?n;
bzero(&pin?sizeof(pin));
pin.sin_family?=?AF_INET;
inet_pton(AF_INET?IP?&pin.sin_addr);
pin.sin_port??=?htons(port);
sock_fd?=?socket(AF_INET?SOCK_STREAM?0);
if(sock_fd?==?-1)
{
perror(“call?to?socket“);
exit(1);
}
n?=?connect(sock_fd?(void?*)&pin?sizeof(pin));
if(n?==?-1)
{
perror(“call?to?connect“);
exit(1);
}
return?sock_fd;
}
void?*thr_gui(void?*arg)
{
gui_main();
}
/*?you?see?the?first?from?the?client?*/
void?first_print_select(int?fd)
{
int?ch;
int?client_select_flag?=?0;
do
{
printf(“\nplease?input?\‘r\‘?to?register?and?input?\‘l\‘?to?load?\n“);
?
ch?=?getchar();
while((getchar())?!=?‘\n‘);
if(ch?==?‘r‘)
{
client_reg_deal(fd);
client_select_flag?=?1;
}
else?if(ch?==?‘l‘)
{
client_load_deal(fd);
client_select_flag?=?1;
}
}while(client_select_flag?!=?1);
}
/*??create?a?pthread?to?deal?the?chat?*/
void?deal_connect(int?sock_fd)
{
int?id;
int?n;
pthread_t?tid;
char?buf[MAXLINE];
first_print_select(sock_fd);
if(?0?!=?pthread_create(&tid?NULL?thr_gui?NULL)?)
{
printf(“can?not?create?gui!\n“);
exit(1);
}
usleep(200);
pthread_create((void?*)&idNULL(void?*)thread(void?*)sock_fd);
while(1)
{
read_from_client(buf);
?client_information_judge_deal(bufsock_fd);
write_to_server(bufsock_fd);
memset(buf0MAXLINE);
}
n?= close(sock_fd);
if(n?==?-1)
{
perror(“call?to?close“);
exit(1);
}
exit(0);
}
/*----------------------------------------------*/
/*?the?third?*//*3^*/
/*??the?pthread?function?circle?to?read?and?the?write?to?client?*/
void?thread(int?sock_fd)
{
int?n;
char?*buf?=?(char?*)malloc(MAXLINE);
while(1)
{
memset(buf0MAXLINE);
n?=?read_from_server(sock_fdbuf);
if(?n?==?-1)
{
perror(“call?to?read“);
exit(1);
}
if((buf[0]?==?‘9‘?&&?buf[1]?==?‘9‘)?||?(buf[0]==?‘8‘?&&?buf[1]?==?‘8‘))
{
plist?new;
new?=(plist)?malloc?(sizeof(str
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????364032??2008-09-09?21:04??em
?????文件?????668672??2007-02-09?14:16??em
?????文件??????11528??2007-02-12?15:01??em
?????文件??????39595??2007-02-09?14:48??em
?????文件???????9295??2007-02-09?12:48??em
?????文件????????665??2007-02-08?14:14??em
?????文件????????280??2007-02-08?14:10??em
?????文件???????2944??2007-02-09?09:15??em
?????文件???????3208??2007-02-09?14:17??em
?????文件????????407??2007-02-08?14:24??em
?????文件???????4612??2007-02-09?14:48??em
?????文件???????4507??2007-02-07?21:05??em
?????文件????????108??2007-02-06?18:23??em
?????文件????????235??2007-02-09?09:15??em
?????文件???????1034??2007-02-08?21:58??em
?????文件????????270??2007-02-08?21:56??em
?????文件????????336??2007-02-09?10:36??em
?????文件????????900??2007-02-09?16:04??em
?????文件????????512??2007-02-08?21:18??em
?????文件????????109??2007-02-08?21:51??em
?????文件??????39667??2007-02-09?11:32??em
?????文件??????76635??2007-02-09?10:19??em
?????文件??????70043??2007-02-09?10:47??em
?????文件?????363008??2008-07-14?20:24??em
?????文件?????668672??2007-02-09?14:16??em
?????文件?????????50??2007-02-09?11:29??em
?????文件????????221??2007-02-09?09:44??em
?????文件????????219??2007-02-09?15:56??em
?????文件???????4169??2007-02-09?16:19??em
?????文件????????460??2007-02-09?09:44??em
............此處省略25個文件信息
評論
共有 條評論