⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scd.h

📁 在RedHad9 下实现文字界面的聊天程序。此源码示范了C语言的socket通信编码;RedHad下如何编译c代码。内附说明文档详细说明了socket通信原理和代码解释。
💻 H
字号:
#include<stdio.h>
#include<strings.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<pthread.h>
#include<arpa/inet.h>
#include<netdb.h>

#define PORT 7053
#define NAMESIZE 100
#define PASSWD 128
#define HOSTSIZE 30
#define COMMANDSIZE 100
#define BACKLOG 500
#define MAXDATASIZE 1000


#define extent 53 
#define cr 0x0d 
#define lf 0x0a 
#define rubout 0x08

struct ARG
{
	int connfd;
	struct sockaddr_in client;
};

struct clientsInfo
{
	int connectfd;   //return value of accept
	char nickname[NAMESIZE];
	char hostname[HOSTSIZE];
	char passwd[PASSWD];
	struct clientsInfo* next;
};

static pthread_mutex_t a_mutex = PTHREAD_MUTEX_INITIALIZER;
static struct clientsInfo* clients=NULL;
static struct clientsInfo* last_client=NULL;
static int clientsCount;
static char errbuf[]="This nickname has been occupied! Choose another one!\nInputName:";
static char cmdbuf[MAXDATASIZE];
static char quitbuf[]="Byte !\n";
static char cmderrbuf[]="Wrong format of changing nickname !";
static char m_buf[]="Wrong format of sending to message to special client !";
static char changerrbuf[]="This nickname has been occupied! Choose another one!:";
static char pwdbuf0[] ="Fail to change password !Check the format of your command !";
static char pwdbuf1[] ="Change password successful !";
static char errsendbuf[] ="No client with such a nickname to sent to !";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -