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

📄 network.cpp

📁 即时通信程序(类似于QQ,MSN) 用C写的
💻 CPP
字号:
/*     *   This program is free software; you can redistribute it and/or modify *   it under the terms of the GNU General Public License as published by *   the Free Software Foundation; either version 2 of the License, or *   (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * *********************************************************************************/ #include "network.h"/** * \fn network::network() * \param int port : le port * \return Rien. * \brief Constructeur de la classe server. Ne fait rien.. */network::network(int tmp_port){  this->remove_id = -1;  this->liste_clients = NULL;  this->client_fd = -1;		//descripteur de fichier pour le mode client  this->debug = 0;		//flag debug off par d閒aut  this->port = tmp_port;	//affecte le port  this->liste_in = NULL;	//initialise le buffer d'entr閑  this->liste_out = NULL;	//initialise le buffer de sortie  if(this->debug) printf("#Network > Module network charg閈n");  #ifdef _WIN32   WSADATA wsaData;   int wsaret=WSAStartup(0x101,&wsaData);   if(wsaret)	     return;  #endif}/** * \fn network::~network() * \param Aucun * \return Rien. * \brief Destructeur de la classe server. Ferme le socket */network::~network(){    close(listener);  if(this->debug) printf("#Network > Module network d閠ruit\n");}/** * \fn network::set_debug(short) * \param short dbg : activer ou non le mode debug * \return Rien. * \brief Active ou non le mode debug */void network::set_debug(short dbg){    this->debug = dbg;}/** * \fn int network::envoi(int, char *, char*) * \param - int destinataire : l'id du client * \param - char *tag : le tag * \param - char *valeur : la valeur affect閑 au tag * \return Rien. * \brief Forme un paquet et l'ajoute au buffer de sortie */intnetwork::envoi(int destinataire, char *tag, char*valeur){ struct _paquet *paquet; paquet = (struct _paquet *)malloc(sizeof(struct _paquet)); if(destinataire != -1)  paquet->destinataire = destinataire; else  paquet->destinataire = this->client_fd; strcpy(paquet->tag, tag); strcpy(paquet->valeur, valeur); return(envoi_paquet(paquet));}//TODO Lors d'une fermeture de client, supprimer toutes les entr閑s du file descriptor./** * \fn int network::envoi_paquet(struct _paquet *) * \param struct _paquet *paquet: le paquet 

⌨️ 快捷键说明

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