【并发服务器系列】2 select模型
2013-01-22 05:39
471 查看
【并发服务器系列】2 select模型 - 邓维 - 博客园
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
【并发服务器系列】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
相关文章推荐
- 【并发服务器系列】2 select模型
- (五十三)高并发服务器——多路IO转接机制Select模型
- 【并发服务器系列】1 停等模型
- 【并发服务器系列】3 epoll模型
- UDP并发服务器模型 二:select机制
- Select I/O模型来实现一个并发处理多个客户端的TCP服务器 <转>
- 几种并发服务器模型的实现:多线程,多进程,select,poll,epoll
- Select I/O模型来实现一个并发处理多个客户端的TCP服务器
- 几种并发服务器模型的实现:多线程,多进程,select,poll,epoll
- 并发服务器系列】3 epoll模型 - 邓维 - 博客园
- 几种并发服务器模型的实现:多线程,多进程,select,poll,epoll - rail
- 使用Select I/O模型来实现一个并发处理多个客户端的TCP服务器
- Linux 网络编程——并发服务器的三种实现模型
- LINUX环境并发服务器的三种实现模型
- Ruby Web 服务器的并发模型与性能
- 高效并发服务器模型
- LINUX环境并发服务器的三种实现模型
- 网络服务器的几种并发服务模型
- Linux网络编程服务器模型选择之并发服务器(下)
- Linux下一个单进程并发服务器的实例 使用select