摘要: #include <stdio.h>#include <errno.h>#include <stdlib.h>#include <unistd.h>#include <signal.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <string.h>#include <sys/types.h>#include <sys/select.h>#include 阅读全文
posted @ 2012-11-01 16:20 孤火 阅读(188) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <errno.h>#include <stdlib.h>#include <unistd.h>#include <signal.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <string.h>#include <sys/types.h>#include <sys/select.h>#define S 阅读全文
posted @ 2012-11-01 16:19 孤火 阅读(161) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <unistd.h>#include <fcntl.h>#include <time.h>#include <sys/time.h>#include <errno.h>#include <stdlib.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <string.h>#include <sys/ 阅读全文
posted @ 2012-11-01 16:18 孤火 阅读(182) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <errno.h>#include <stdlib.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <string.h>#include <sys/types.h>#include <sys/select.h>#define SERV_ADDR "127.0.0.1"#define SERV_PORT 53 阅读全文
posted @ 2012-11-01 16:17 孤火 阅读(152) 评论(0) 推荐(0) 编辑
摘要: /************************ * client ************************/#include <stdio.h>#include <errno.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <string.h>#define SERV_ADDR "127.0.0.1"#define SERV_PORT 5358#define BUF_LEN 1024 阅读全文
posted @ 2012-11-01 16:16 孤火 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 1、I/O复用同步I/O阻塞I/O模型非阻塞I/O模型I/O复用模型信号驱动I/O模型异步I/O模型唯一需要注意的是信号驱动I/O与异步I/O的区别,信号驱动I/O是指当描述符可读/可写了,内核通知应用程序去读/写。而异步I/O是指在应用程序收到信号时,读/写已经由完成。2、改进后的str_cli函数#include <stdio.h>#include <errno.h>#include <stdlib.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/ 阅读全文
posted @ 2012-11-01 16:11 孤火 阅读(291) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <unistd.h>#include <sys/socket.h>#include <netinet/in.h>#include <errno.h>#include <signal.h>#include <sys/wait.h>#include <sys/types.h>#include <string.h>#include <stdlib.h>#include <pthread.h>#define SERV_ 阅读全文
posted @ 2012-11-01 16:04 孤火 阅读(142) 评论(0) 推荐(0) 编辑
摘要: View Code #include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <string.h>#include <netinet/in.h>#include <sys/socket.h>#include <sys/types.h>#include <errno.h>#include <sys/select.h>#define BUF_LEN 1024#define SERV_PORT 5358#define FD 阅读全文
posted @ 2012-11-01 16:02 孤火 阅读(215) 评论(0) 推荐(0) 编辑
摘要: /************************ * client ************************/#include <stdio.h>#include <errno.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <string.h>#define SERV_ADDR "127.0.0.1"#define SERV_PORT 5358#define BUF_LEN 1024 阅读全文
posted @ 2012-11-01 16:01 孤火 阅读(230) 评论(0) 推荐(0) 编辑
摘要: epoll模型有两种工作模式,ET和LT,两种模式下都有一些细节值得注意,以下是一些思考:一、ET模式下Q1: 调用accept时,到底TCP完成队列里有多少个已经建立好的连接?这里又得分情况来说:没有连接。这种情况发生在TCP连接被客户端夭折,即在服务端调用accept之前客户端给出一个RST。该RST导致刚刚建立好的连接从服务器 端的TCP完成队列中被移出。源自berkeley的实现会在内核处理该事件,并不会将该事件通知给服务程序,如果套接口被设置为阻塞模式,就会导致 accept函数被阻塞,程序挂起,一直要等到下一个连接到来,这也是为什么采用非阻塞的accept的原因;其他的实现通常会返 阅读全文
posted @ 2012-11-01 15:57 孤火 阅读(258) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <string.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <sys/types.h>#include <sys/socket.h>#include <sys/epoll.h>#include <netinet/in.h>#include <pthread.h>#include <stdlib.h>#define SERV_ 阅读全文
posted @ 2012-11-01 15:50 孤火 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 最近在学习linux环境高级编程,多进程编程算是编程中的最重要的一个部分了,本文让我学习和明白了很多,所以转载过来。让更多想多线程编程的人学习。只有顶到首页才能让更多的人学习。文章摘要: 多线程程序设计的概念早在六十年代就被提出,但直到八十年代中期,Unix系统中才引入多线程机制,如今,由于自身的许多优点,多线程编程已经得到了广泛的应用。本文我们将介绍在Linux下编写多进程和多线程程序的一些初步知识。-------------------------------------------------------------------------------- 正文: Linux下的多... 阅读全文
posted @ 2012-11-01 15:46 孤火 阅读(345) 评论(0) 推荐(0) 编辑
摘要: 在做网络服务的时候tcp并发服务端程序的编写必不可少。tcp并发通常有几种固定的设计模式套路,他们各有优点,也各有应用之处。下面就简单的讨论下这几种模式的差异: 1、 单进程,单线程模式 在accept之后,就开始在这一个连接连接上的数据收接收,收到之后处理,发送,不再接收新的连接,除非这个连接的处理结束。 优点: 简单。 缺点: 因为只为一个客户端服务,所以不存在并发的可能。 应用: 用在只为一个客户端服务的时候。 2、 多进程模式 accept返回成功时候,就为这一个连接fork一个进程,专门处理这个连接上的数据收发,等这个连接处理结束之后就结束这个进程。 优点: 编程相对简单,不用考.. 阅读全文
posted @ 2012-11-01 11:21 孤火 阅读(276) 评论(0) 推荐(0) 编辑
摘要: 服务器设计技术有很多,按使用的协议来分有TCP服务器和UDP服务器。按处理方式来分有循环服务器和并发服务器。1 循环服务器与并发服务器模型在网络程序里面,一般来说都是许多客户对应一个服务器,为了处理客户的请求,对服务端的程序就提出了特殊的要求。目前最常用的服务器模型有:·循环服务器:服务器在同一时刻只能响应一个客户端的请求·并发服务器:服务器在同一时刻可以响应多个客户端的请求1.1 UDP循环服务器的实现方法:UDP循环服务器每次从套接字上读取一个客户端的请求->处理->然后将结果返回给客户机。因为UDP是非面向连接的,没有一个客户端可以老是占住服务端。只要处理 阅读全文
posted @ 2012-11-01 10:48 孤火 阅读(385) 评论(0) 推荐(0) 编辑
摘要: 1 未来永远从现在开始。2 也许我不是最优秀的,但我是最努力的。3 没有永远的胜利,只有永远的努力。4 艰苦是面临,挫折是经验,努力是桥梁,成功是彼岸。5 自己把自己说服了,是一种理智的胜利;自己被自己感动了,是一种心灵的升华;自己把自己征服了;是一种人生的成熟。6 对别人宽容是一种储蓄,对自己宽容是一次透支7 为草应做兰,为木应做松。8 成功是优点的发挥,失败是缺点的累积。9 学习使人丰富知识,知识使人提升才能,才能使人创造业绩。10 不管是金点子,还是银点子,得不到落实都是空点子。11 不怕“难”字当道,就怕“懒”字沾身。12 闪光的未必都是金子,而沉默的也不一定就是石头。13 今天的成绩 阅读全文
posted @ 2012-11-01 10:27 孤火 阅读(182) 评论(0) 推荐(0) 编辑