院系:計算機與資訊工程學院
班級:09級計算機應用2班
姓名:李敏敏
學號:0906042023
伺服器——客戶端
/*****************server.c******************/
#include
#include
#include
#include
#include "wrap.h"
#define maxline 80
#define serv_port 8000
int main(int argc, char **argv)
if(i == fd_setsize)
fd_set(connfd,&allset);/* add new descriptor to set */
if(connfd > maxfd)
maxfd= connfd;/* for select */
if(i > maxi)
maxi= i;/* max index in client array */
if(--nready == 0)
continue;/*no more readable descriptors */ }
for(i = 0; i <= maxi; i++) else
//把已讀到的資料傳送給每乙個連線的客戶端
} }
if(--nready == 0)
break;/*no more readable descriptors */ }
} }
}/**********************client.c ****************/
#include
#include
#include
#include
#include "wrap.h"
#include
#include
#include
#define maxline 80
#define serv_port 8000
int main(int argc, char *argv)
}if(pid == 0)
close(sockfd);
return0; }
執行過程:
伺服器:
[root@localhost ~]# cd desktop
[root@localhost desktop]# gcc server.c -o server
[root@localhost desktop]# ./server
[root@localhost desktop]# ./server
received from 127.0.0.1 at port 44816
received from 127.0.0.1 at port 44818
received from 127.0.0.1 at port 47372
開啟三個客戶端:
第乙個:
[root@localhost desktop]# gcc client.c -o client
[root@localhost desktop]# ./client
wodemingzi
wodemingzi
hello
hello
xianzaishi
xianzaishi
第二個:
[root@localhost ~]# cd desktop
[root@localhost desktop]# ./client
wodemingzi
hello
xianzaishi
第三個:
[root@localhost ~]# cd desktop
[root@localhost desktop]# ./client
xianzaizhendehenhao
xianzaizhendehenhao
0
給主人留下些什麼吧!~~
伺服器與客戶端
建立socket操作,建立流式套接字,返回套接字型大小socksrv socket socket int af,int type,int protocol 第乙個引數,指定位址簇 tcp ip只能是af inet,也可寫成pf inet socket socksrv socket af inet,s...
客戶端與伺服器
cs與bs 軟體使用方式上的兩種劃分 c s client server pc客戶端與伺服器架構 特點 在伺服器當中就主要是乙個資料庫,把所有業務邏輯都交給客戶端來完成 優點 較為安全,使用者介面豐富,客戶體驗好 缺點 每次公升級都要重新安裝,針對不同的作業系統開發,可移植性差 b sbrowser...
伺服器與客戶端 client
include include include include include include include define serv port 9000 define buff size 1024 struct user void fillmsg struct user userinfo void...