首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Python 中的 socket 模块

import socket help(socket)     Functions:     socket() -- create a new socket object     socketpair() -- create a pair of new socket objects [*]     fromfd() -- create a socket object from an open file descriptor [*]     gethostname() -- return the current hostname     gethostbyname() -- map a hostname to its IP number     gethostbyaddr() -- map an IP number or hostname to DNS info     getservbyname() -- map a service name and a protocol name to a port number     getprotobyname() -- map a protocol name (e.g. 'tcp') to a number     ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order     htons(), htonl() -- convert 16, 32 bit int from host to network byte order     inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format     inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)     ssl() -- secure socket layer support (only available if configured)     socket.getdefaulttimeout() -- get the default timeout value     socket.setdefaulttimeout() -- set the default timeout value     create_connection() -- connects to an address, with an optional timeout and optional source address. 简单的介绍一下这些函数的作用: 一、socket类方法(直接可以通过socket 类进行调用) 1、gethostbyname() -- map a hostname to its IP number

02

tcp socket的发送与接收缓冲区

1) 应用程序可通过调用send(write, sendmsg等)利用tcp socket向网络发送应用数据,而tcp/ip协议栈再通过网络设备接口把已经组织成struct sk_buff的应用数据(tcp数据报)真正发送到网络上,由于应用程序调用send的速度跟网络介质发送数据的速度存在差异,所以,一部分应用数据被组织成tcp数据报之后,会缓存在tcp socket的发送缓存队列中,等待网络空闲时再发送出去。同时,tcp协议要求对端在收到tcp数据报后,要对其序号进行ACK,只有当收到一个tcp 数据报的ACK之后,才可以把这个tcp数据报(以一个struct sk_buff的形式存在)从socket的发送缓冲队列中清除。 tcp socket的发送缓冲区实际上是一个结构体struct sk_buff的队列,我们可以把它称为发送缓冲队列,由结构体struct sock的成员sk_write_queue表示。sk_write_queue是一个结构体struct sk_buff_head类型,这是一个struct sk_buff的双向链表,其定义如下:

02
领券