您正在查看 "Networking" 分类下的文章
2009-09-03 12:35
标准的udp客户端开了套接口后,一般使用sendto和recvfrom函数来发数据,最近看到ntpclient的代码里面是使用send函数直接法的,就分析了一下,原来udp发送数据有两种方法供大家选用的,顺便把udp的connect用法也就解释清楚了。
方法一:
socket----->sendto()或recvfrom()
方法二:
socket----->connect()----->send()或recv()
首先从这里看出udp中也是可以使用connect的,但是这两种方法到底有什么区别呢?首先把这四个发送函数的定义列出来:
int send(int s, |
2009-08-06 10:22
发送端:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <errno.h>
#include <netinet/in.h>
#define PORTNUM 5000
#define GROUPIP "224.0.1.1"
int main()
{
int sock_id;
struct sockaddr_in addr;
char buf[] = "This is a test message.";
socklen_t len;
int ret;
/* open a socket. only udp support multicast */
if ((so |
2008-02-28 13:00
如何减少TIME_WAIT
前言:经常检查Apache的连接数,同样会发现很多无用的Time_Wait连接。有人说这是正常的,是因为一个请求中途中断造成的;还有人说微软的 IE连接时产生的Time_wait会比用Firefox连接时多。个人认为有一定的Time_wait是正常的,如果超过了连接数的比例就不是很正常, 所以还是找来方法解决一下。
检查net.ipv4.tcp_tw当前值,将当前的值更改为1分钟:
[root@aaa1 ~]# sysctl -a|grep net.ipv4.tcp_tw
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_tw_recy |
2007-09-22 08:53
2007-06-01 14:06
IP包捕获的几种可行的方法:
>
> 法一: 通过AF_INET加SOCK_RAW来做, 这是一个通用的技术,但一般来说通用就不能高效,
> 去除DMA的拷贝,CPU还要经过两次拷贝才能将数据送到用户态。并且这种技术只能捕获IP包,以下几种都可以捕获 |
2007-05-18 14:50
E100’s memory allocation.
First, it allocates a DMA buffer ring for the NIC by using the e100_rx_alloc_list(), it does that in a loop, as follow:
unsigned int i, count = nic->params.rfds.count;
|
|
|