您的位置:首页 > 其它

【并发服务器系列】2 select模型

2013-01-22 05:39 471 查看
【并发服务器系列】2 select模型 - 邓维 - 博客园

【并发服务器系列】2 select模型

some of the codes are the same with previous article. I just list the different code here .

chat_server.cpp

View Code
#include "chat.h"

extern int sock_client_init(const char*ipaddress, uint16_t server_port);

extern ssize_t p_write_to_p(int clientfd, const char *msg);
extern ssize_t p_read_from_p(int clientfd);
void chat_client(const char* linkin_ip)
{
printf("chat client start %s \n", linkin_ip);
int clientfd = sock_client_init(linkin_ip, SERVER_PORT);
if(clientfd < 0 )
{
return ;
}
ssize_t iw = p_write_to_p(clientfd, "hello, this is client");
printf(" iwrite = %d \n", iw);
ssize_t ir = p_read_from_p(clientfd);
printf(" ireadback = %d \n", ir);
if( ir == 0)
printf(" connection close by server\n");


usage:

to start a server: ./chat
to start some clients: ./chat localhost & ./chat localhost&./chat localhost & ./chat localhost &

Performance:Testing Machine: Local test ,OS: Fedora 14(Linux 2.6.35) 2 Cores:E3200@2.4GHz, Memory: 2GiB
Result: Handles 100~200 clients per sec

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: