资源简介
个人在linux下用GTK写的模仿QQ聊天程序,包含客户一个服务器一个客户端,有私聊,发送系统消息,聊天记录,发送文件,发送电子邮件,用到的知识:C/C++,GTK,MYSQL,SOCKET,多线程,本程序仅用于学习交流,站在巨人的肩膀上,学习更多的知识。
代码片段和文件信息
#include “callbacks.h“
int wrilog = 0 wriadd = 0 jinji = 0;
int log_stut = 0 add_stut = 0;
int fdstatu = 1dia=0;
int recourd=1;
int serverport;
char serverip[30];
char ch_dialog[100];
int opt = 1 maxfd = -1 k = 0 top = 1;
int xx = 0;
GtkWidget *window1;
//+++++++++++++查找还没有使用的连接状态数组++++++++++++++++++++++++
void add_sockset(fd_set * sockset int sockfd int user_link int add[messcount][2])
{
int i;
FD_ZERO(sockset);
if (xx)
FD_CLR(sockfd &allset);
else
FD_SET(sockfd sockset);
FD_SET(user_link sockset);
FD_SET(1 sockset);
for (i = 0; i < messcount; i++) {
if (add[i][0] != -1) {
FD_SET(add[i][1] sockset);
}
}
}
//+++++++++++++++++++++++++++++
int addr(void)
{
int i;
for (i = 0; i < messcount; i++)
if (add[i][0] == -1)
return i;
}
//+++++++++++++++++++++++++
int tu_mess(void)
{
int i;
for (i = 0; i < messcount; i++)
if (allmess[i].tu == 0)
return i;
}
//++++++++++++++++++++++++
int max_fd(int ab int ac)
{
if (ab > ac)
return ab;
else
return ac;
}
//++++++++++++++++关闭文件描述符+++++++++++++++++
void func_close (void)
{
close(sockfd);
for (i = 0; i < messcount; i++) {
if (add[i][0] != -1) {
close(add[i][1]);
}
}
}
//++++++++++++++++退出函数+++++++++++++++++
void on_delete_event(GtkWidget * widget gpointer date)
{
printf(“aaaaadddddd\n“);
func_close();
gtk_main_quit();
exit(0);
//return FALSE;
}
//++++++++++++++++创建与服务器的连接函数+++++++++++++++++
int initial_server(void)
{
char *POPMessage[]={
“USER myqqmail\r\n“
“PASS 123456123\r\n“
NULL};
char buf[5000];
int in;
int num1num2num3num4num5num6num7num8num9num10num11num12;
int sockfd_mailiLength;
struct sockaddr_in server_mail;
int iMsg=0;
if((sockfd_mail=socket(AF_INETSOCK_STREAM0))==-1){
perror(“ socket error“);exit(1);
}
server_mail.sin_family=AF_INET;
server_mail.sin_port=htons(110);
server_mail.sin_addr.s_addr=inet_addr(“123.125.50.23“);
bzero(&(server_mail.sin_zero)8);
if(connect(sockfd_mail(struct sockaddr *)(&server_mail)sizeof(struct sockaddr))!=-1){
iLength=recv(sockfd_mailbufsizeof(buf)0);
buf[iLength]=‘\0‘;
printf(“received:%s\n“buf);
do
{
send(sockfd_mailPOPMessage[iMsg]strlen(POPMessage[iMsg])0);
printf(“发送帐号:%s“POPMessage[iMsg]);
memset(buf‘\0‘1024);
iLength=recv(sockfd_mailbufsizeof(buf)0);
buf[iLength]=‘\0‘;
iMsg++;
printf(“接收信息:%s\n“buf);
}while(POPMessage[iMsg]);
send(sockfd_mail“RETR 1\r\n“strlen(“RETR 1\r\n“)0);
memset(buf‘\0‘5000);
// iLength=recv(sockfd_mailbuf10240);
// buf[iLength]=‘\0‘;
// iMsg++;
// printf(“接收receive:%s\n“buf);
//开始接收邮件
num1=num2=num3=0;
n=0;
int k=0jx=0;
char a[2]*tokenb=20;
for(i=0;i<5000;i++){
n++;
recv(sockfd_maila10);
if(strcmp(a“S“)==0) num1=n;
if(strcmp(a“u“)==0) num2=n;
if(strcmp(a“b“)==0) num3=n;
if(strcmp(a“j“)==0) num4=n;
if(strcmp(a“e“)==0) num5=n;
if(strcmp(a“c“)==0) num6=n;
if(strcmp(a“t“)==0
评论
共有 条评论