资源简介

此资源是基于Linux 环境下的Socket通信编写的代码,里面融合了TCP/IP 通信,UDP通信,GTK,等知识,而且使用了I/O复用,在性能上有着自己的优势。这个作品是我在课程设计的时候参考一个代码做的,我在原作者的基础上做了自己的改善。也谢谢原作者对于我的帮助!如果你想学习Linux C 可以下载,希望对你有用。帮助我写在了client里面,你可以参考!

资源截图

代码片段和文件信息

/*---------------xc_qq.c------------
gcc -Wall -o client_qq client_qq.c ‘pkg-config --cflags --libs gtk+-2.0 gthread-2.0‘ -export-dynamic -lpthread
第一行是运行的命令,我将图标放在了包里,你需要建立一个ico的文件夹,将图标放进去,或者更改程序里面的路径。
*/
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include “wrap.h“
#include “mygtk.h“
#define MAXLINE 800

static char *fengefu = “+“;

pthread_t ntid;
static char list_name[MAXLINE][MAXLINE] receive_msg_buf_name[MAXLINE][MAXLINE];
static pthread_t tid;
/*******************************/
static char msg_ip[MAXLINE]msg_port[MAXLINE];
/*********************************/
static char myname[MAXLINE] myip[MAXLINE] msg_buf[MAXLINE] myport[MAXLINE];
/**************文件传输相关变量开始*************/
static char file_from_name[MAXLINE] filename[MAXLINE] receive_ip[MAXLINE] receive_port[MAXLINE] disrecv_from_name[MAXLINE];
int new_file = -1 get_ip_statue = -1;
/**************文件传输相关变量结束*************/
int group_send=-1;
char group_message[MAXLINE];
int err;
static int retvalue = 0 c_icon = -1;
//static int ifshow=-1;
char buf[MAXLINE];
int inet_pton(int af const char *src void *dst);
static int sockfd n;

static int connect_ser(char server_ip[] int server_port);
static void show_login();

void init_list_name()
{
int i = 0;
for (i = 0; i < MAXLINE; i++) {
bzero(list_name[i] MAXLINE);
strcpy(list_name[i] “null“);
}
}

void init_receive_msg_buf_name()
{
int i = 0;
for (i = 0; i < MAXLINE; i++) {
bzero(receive_msg_buf_name[i] MAXLINE);
strcpy(receive_msg_buf_name[i] “null“);
}
}

/* 列表代码开始 */

enum {
COLUMN = 0
NUM_COLS
};
GtkWidget *view;
GtkWidget *label_myname;
char count_online[100];
void on_changed(GtkWidget * widget gpointer statusbar)
{

GtkTreeIter iter;
GtkTreeModel *model;
char *value;
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(widget) &model &iter)) {

gtk_tree_model_get(model &iter COLUMN &value -1);
gtk_statusbar_push(GTK_STATUSBAR(statusbar) gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar) value) value);
char win_name[MAXLINE];
sprintf(win_name “%s+正在和+%s+聊天\n“ myname value);
int i = 0;
for (i = 0; i < MAXLINE; i++) {
if (strcmp(receive_msg_buf_name[i] value) == 0) {
return;
}
}

if (strcmp(value count_online) != 0 && strcmp(value “离线好友(0)“) != 0 && strcmp(value “获取列表失败!请重新登录!“) != 0) {
for (i = 0; i < MAXLINE; i++) {
if (strcmp(receive_msg_buf_name[i] “null“)== 0) {
strcpy(receive_msg_buf_name[i] value);
break;
}
}

          //pthread_t show_chat_tid;
          //void *win_title = (void *)win_name; //类型转换
        //void *sockfe = (void *)sockfd; //类型转换

//pthread_create(&ntid NULL thr_fn sockfe);
         //pthread_create(&show_chat_tid NULL show_chat_window_thr NULL);
show_chat_window(win_name);
}
g_free(value);
}

}

static void remove_all()
{
GtkTreeStore *treestore;

treesto

评论

共有 条评论