女人被狂躁到高潮视频免费无遮挡,内射人妻骚骚骚,免费人成小说在线观看网站,九九影院午夜理论片少妇,免费av永久免费网址

當前位置:首頁 > > 充電吧
[導讀]? ? ? ? ? ? ? ? ? ? ? ? ? ? 基于linux下的聊天程序設計與實現(xiàn)一、 ?實現(xiàn)的內容及要求:? ? ? 用C語言編程實現(xiàn)linux簡單的聊天室功能。? 用戶程序命名為clie

? ? ? ? ? ? ? ? ? ? ? ? ? ? 基于linux下的聊天程序設計與實現(xiàn)

一、 ?實現(xiàn)的內容及要求:

? ? ? 用C語言編程實現(xiàn)linux簡單的聊天室功能。


? 用戶程序命名為client.c;服務器程序命名為server.c? 綁定端口等信息見實驗方法內容;? 要求client可以通過socket連接server? 在client,提示輸入服務器ip? 若連接server 的socket建立成功,返回提示信息? Client輸入的聊天內容在client端(多個client端)和server端同時顯示;? 多個client可同時接入server,進入聊天室,最多支持20個client;? Client端輸入quit退出連接,server端提示client退出。? 可選擇使用多線程實現(xiàn)多客戶端;? 其他細節(jié)見輸出結果;


??????

二、方法及內容

1.?????需要的頭文件

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

?

2.?????主要的常量變量

客戶端:

#define TRUE 1

#define PORT 5000

int quit=0;???? //quit表示是否用戶確定退出

?

服務器端:

#define MAXLINE 1000? //在一條消息中最大的輸出字符數(shù)

#define LISTENQ 20????????????? //最大監(jiān)聽隊列

#define PORT 5000?????????????? //監(jiān)聽端口

#define MAXFD 20??????????????? //最大的在線用戶數(shù)量

void *get_client(void *);????

int i,maxi=-1;//maxi表示當前client數(shù)組中最大的用戶的i值

int client[MAXFD];


3.主要模塊

客戶端:

intmain(void)

void*get_server(void* sockfd)??

//get_server函數(shù),用于接受服務器轉發(fā)的消息


服務器端:

??? intmain()?

??? void*get_client(void *sockfd) //運行get_client函數(shù),處理用戶請求

?

三.完整代碼實現(xiàn)


注:參考socket編程

?

/******* 客戶端程序client.c ************/

#include

#include

#include

#include

#include

#include

#include

#include

?

?

#define TRUE 1

#define PORT 5000

?

static int sockfd;

void recvfromserver()??????? //接受服務器消息線程入口函數(shù)

{

?????? charmes[1024];

?????? int nbytes=0;

?

?????? while(1)

?????? {

????????????? memset(mes,0,sizeof(mes));

????????????? nbytes=read(sockfd,mes,sizeof(mes));

????????????? if(nbytes>0)

????????????? {

???????????????????? mes[nbytes]='