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
相关文档:
安装openssh 服务端
sudo apt-get install openssh-server openssh-client
windows 下客户端
puTTY
常用命令:
一.Ls 查看目录命令
一般放在home 目录下
Ls –l / 根目录下的列表
Ls –a / 根目录下所有的文件
Ls –la 组合的选项
Ls &n ......
管理员想要提高Linux管理效率是要遵循一些管理技巧的,这里简单介绍有关Linux管理效率的三个技巧:卸载无响应的 DVD 驱动器、恢复出现问题的屏幕、屏幕协作。相信他们会对管理员效率有提高。
技巧 1:卸载无响应的 DVD 驱动器
网络新手的经历:按下服务器(运行基于 Redmond 的操作系统)DVD 驱动器上的 Eject 按钮时, ......
Book Note: Linux Device Driver Dos and Don'ts
http://janitor.kernelnewbies.org/docs/driver-howto.html
what a hardened (robust) device
driver should mean and how it should be implemented and measured.
1.3 Robust device drivers
-Follows the Linux CodingStyle.
-Efficient in managing faults and ha ......
前言:
我们在这一节将要讨论linux下文件操作的各个函数.
1.文件的创建和读写
2.文件的各个属性
3.目录文件的操作
4.管道文件
--------------------------------------------------------------------------------
1。文件的创建和读写
......