易截截图软件、单文件、免安装、纯绿色、仅160KB

linux socket的select函数例子

使用select函数可以以非阻塞的方式和多个socket通信。程序只是演示select函数的使用,功能非常简单,即使某个连接关闭以后也不会修改当前连接数,连接数达到最大值后会终止程序。
1. 程序使用了一个数组fd_A,通信开始后把需要通信的多个socket描述符都放入此数组。
2. 首先生成一个叫sock_fd的socket描述符,用于监听端口。
3. 将sock_fd和数组fd_A中不为0的描述符放入select将检查的集合fdsr。
4. 处理fdsr中可以接收数据的连接。如果是sock_fd,表明有新连接加入,将新加入连接的socket描述符放置到fd_A。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define MYPORT 1234    // the port users will be connecting to
#define BACKLOG 5     // how many pending connections queue will hold
#define BUF_SIZE 200
int fd_A[BACKLOG];    // accepted connection fd
int conn_amount;    // current connection amount
void showclient()
{
    int i;
    printf("client amount: %d\n", conn_amount);
    for (i = 0; i < BACKLOG; i++) {
        printf("[%d]:%d  ", i, fd_A[i]);
    }
    printf("\n\n");
}
int main(void)
{
    int sock_fd, new_fd;  // listen on sock_fd, new connection on new_fd
    struct sockaddr_in server_addr;    // server address information
  


相关文档:

实战Linux Bluetooth编程 (七) SDP协议

Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......

[转帖]Linux驱动开发学习的一些必要步骤

 1. 学会写简单的makefile
2. 编一些应用
程序
,可以用makefile跑起来
3. 学会写驱动
的makefile
4. 写一简单char驱动,makefile编译通过,可以insmod, lsmod, rmmod. 在驱动的init函数里打印hello world,insmod后应该能够通过dmesg看到输出

5. 写一完整驱动, 加上read, write, ioctl, polling等� ......

用GCC开发linux应用程序(经典)

用GCC开发linux应用程序(经典)
2009年11月01日 星期日 23:58
作为自由软件的旗舰项目,Richard Stallman 在十多年前刚开始写作 GCC 的时候,还只是把它当作仅仅一个 C程序语言的编译器;GCC 的意思也只是 GNU C Compiler 而已。经过了这么多年的发展,GCC 已经不仅仅能支持 C语言;它现在还支持 Ada 语言、C++ 语言、Ja ......

Linux性能测试工具(转)

Linux系统出现问题时,我们不仅需要查看系统日志信息,而且还要使用大量的性能监测工具来判断究竟是哪一部分(内存、CPU、硬盘……)出了问题。在Linux系统中,所有的运行参数保存在虚拟目录/proc中,换句话说,我们使用的性能监控工具取到的数据值实际上就是源自于这个目录,当涉及到系统高估时,我们就可以修 ......

Unix,Windows,Mac,Linux系统

 一 操作系统分类
http://www.csee.wvu.edu/~jdm/classes/cs258/OScat/
二 操作系统和时间线
http://en.wikipedia.org/wiki/Timeline_of_operating_systems
三 操作系统和公司
http://en.wikipedia.org/wiki/List_of_operating_systems
四 各种操作系统比较
http://en.wikipedia.org/wiki/Comparison_of_operat ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号