91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

群聊模式采用C-S-C模式,即客戶端發送信息給服務端,服務端進行處理返回給其他客戶端。設計模式為服務器多進程響應登錄、注冊,單進程并發客戶聊天操作,客戶端多線程響應服務端反饋。

資源截圖

代碼片段和文件信息

#include?“socketInclude.h“
#include?

//封裝聊天窗體
struct?chat_Widget{
??GtkWidget?*window;
??GtkWidget?*infoSendText*SendButton*showInfoButton;
??GtkWidget?*vbox;
??GtkWidget?*hbox;
??GtkWidget?*label;
??GtkWidget?*text_view;
??GtkTextBuffer?*buffer;
};


int?sockfd;
int?flags=0;//控制線程結束
int?show_click=1;//控制歷史消息可點次數
struct?sockaddr_in?serv_addr;
const?char?*user*password;

//獲取當前系統時間并保存到結構體中
void?current_system_time(int?get_time[])
{
??time_t?rawtime;
??struct?tm?*?timeinfo;?
??time?(?&rawtime?);?
??timeinfo?=?localtime?(?&rawtime?);?
??get_time[0]=timeinfo->tm_year+1900;
??get_time[1]=timeinfo->tm_mon+1;
??get_time[2]=timeinfo->tm_mday;
??get_time[3]=timeinfo->tm_hour;
??get_time[4]=timeinfo->tm_min;
??get_time[5]=timeinfo->tm_sec;
}

//把用戶離線時間寫入文本
void?write_file()
{
??FILE?*fp*fp_backup;
??struct?local_info?user_inforead_info;
??int?time_record[6]time_read[6]new_info=1;
??char?*read_user;
??current_system_time(time_record);
??user_info.year=time_record[0];
??user_info.month=time_record[1];
??user_info.day=time_record[2];
??user_info.hour=time_record[3];
??user_info.minute=time_record[4];
??user_info.second=time_record[5];
??strcpy(user_info.useruser);
??fp=fopen(“/home/localhost/NetChat/NetChatClient/user_login_info““a+“);
??fp_backup=fopen(“/home/localhost/NetChat/NetChatClient/user_login_info_backup““w+“);
??if(fp==NULL)
??{????????????????
????printf(“不能打開文件!\n“);????????????????
????exit(-1);????????
??}
??rewind(fp);
??rewind(fp_backup);
??//保證不同用戶只出現一次
??while(fread(&read_infosizeof(struct?local_info)1fp))
??{
????if(strcmp(read_info.useruser))
????{
??????fwrite(&read_infosizeof(struct?local_info)1fp_backup);
????}
????else
????{
??????new_info=0;
??????fwrite(&user_infosizeof(struct?local_info)1fp_backup);
????}
??}
??if(new_info)
??{
????fwrite(&user_infosizeof(struct?local_info)1fp_backup);
??}
??if?(rename(“/home/localhost/NetChat/NetChatClient/user_login_info_backup“
????“/home/localhost/NetChat/NetChatClient/user_login_info“)?!=?0)
??{
????printf(“重命名出錯!\n“);
??}
??fclose(fp);
??fclose(fp_backup);
}

void?destroy(GtkWidget?*windowgpointer?data)
{
??flags=1;
??close(sockfd);
??write_file();
??printf(“退出聊天\n“);
??gtk_main_quit();
}

//顯示在線人數
void?conn_string(int?countchar?str[])
{
??char?num_string[20];
???sprintf(num_string?“?%d“??count);
??strcat(strnum_string);
}

//把文本寫入text控件里is_Show為1則為顯示歷史消息,否則為當前消息
void?print_word(struct?info_Text?recv_infoconst?char?*local_userGtkTextBuffer?*bufferint?is_Show)
{
??GtkTextIter?startend;
??char?str[1024];
??gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(buffer)&start&end);
??if(strcmp(recv_info.userlocal_user))//是否是自己的信息
??{
????sprintf(str“\t\t\t\t%d:%d:%d-%d:%d:%d\n%s\n\t\t%s\n“?recv_info.fun_Choose.date_Word_Record.year
recv_info.fun_Choose.date_Word_Record.monthrecv_info.fun_Choose.date_Word_Record.dayrecv_info.fun_Choose.date_Word_Record.hour
?

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-11-24?22:25??網絡聊天(優化版)\
?????目錄???????????0??2016-11-15?23:22??網絡聊天(優化版)\NetChat\
?????目錄???????????0??2016-11-19?12:40??網絡聊天(優化版)\NetChat\NetChatClient\
?????文件???????41837??2016-11-19?12:38??網絡聊天(優化版)\NetChat\NetChatClient\CMP
?????文件???????32318??2016-11-19?12:38??網絡聊天(優化版)\NetChat\NetChatClient\NCCliLo
?????文件????????6136??2016-11-19?12:38??網絡聊天(優化版)\NetChat\NetChatClient\NCClientForLogin.c
?????文件???????11286??2016-11-19?12:38??網絡聊天(優化版)\NetChat\NetChatClient\chatMainPro.c
?????文件?????????579??2016-11-17?14:44??網絡聊天(優化版)\NetChat\NetChatClient\mutualStructDef.h
?????文件????????1359??2016-11-17?17:14??網絡聊天(優化版)\NetChat\NetChatClient\socketInclude.h
?????文件?????????224??2016-11-19?12:40??網絡聊天(優化版)\NetChat\NetChatClient\user_login_info
?????目錄???????????0??2016-11-19?12:38??網絡聊天(優化版)\NetChat\NetChatServer\
?????文件???????30871??2016-11-19?12:38??網絡聊天(優化版)\NetChat\NetChatServer\NCSM
?????文件???????10573??2016-11-19?12:38??網絡聊天(優化版)\NetChat\NetChatServer\NCServerMain.c
?????文件?????????509??2016-11-17?10:18??網絡聊天(優化版)\NetChat\NetChatServer\mautulStructDef.h
?????文件????????1388??2016-11-17?17:11??網絡聊天(優化版)\NetChat\NetChatServer\socketInclude.h
?????文件?????????290??2016-11-24?22:26??網絡聊天(優化版)\配置說明.txt

評論

共有 條評論