socket常用的几个函数
来源:互联网 发布:淘宝店铺号怎么隐藏 编辑:程序博客网 时间:2024/05/17 08:14
下面是几个常用的socket函数,当然建立server和client的基本流程中使用的那几个就不写了。
1,htonl,The htonl function converts a u_long from host to TCP/IP network byte order (which is big endian).
htons, ntohs, ntohl功能也类似。
2,getservbyname,得到name(s),service number以及协议和端口号。
3,gethostbyname,根据host name字符串得到IPV4的地址等host信息。
gethostname是根据地址等信息得到host name的字符串。
4,getsockname,根据自己机器的一个socket handle得到全部的该socket信息,包括address family,port等。
而getpeername,根据peer机器来的socket得到该socket的信息
这两个函数,只有在面向连接的协议中使用(TCP)。
5,getsockopt,setsockopt设置socket的option
6,书上一直说阻塞socket和非阻塞socket,直到现在才知道如何做到阻塞和非阻塞。就是这个函数:ioctlsocket。根据MSDN:controls the I/O mode of a socket。
比如:
//-------------------------
// Set the socket I/O mode: In this case FIONBIO
// enables or disables the blocking mode for the
// socket based on the numerical value of iMode.
// If iMode = 0, blocking is enabled;
// If iMode != 0, non-blocking mode is enabled.
u_long iMode = 0;
ioctlsocket(m_socket, FIONBIO, &iMode);
- socket常用的几个函数
- socket编程常用的几个函数
- 几个常用的函数
- 常用的几个函数
- socket 的常用函数
- 几个常用的日期函数
- 几个常用的日期函数
- 几个常用的Javascript函数
- 几个常用的Javascript函数
- 几个常用的Javascript函数
- 几个常用的Javascript函数
- 几个常用的Javascript函数
- 几个常用的Javascript函数
- 几个常用的Javascript函数
- 几个常用的Javascript函数
- 几个常用的Javascript函数
- 几个常用的Javascript函数
- 几个常用的Javascript函数
- 常用正则表达式
- c/c++ windows控制台 timmer
- 五种查询Internet连接状态的方法
- 一行图片新闻向上滚动,带间歇停止
- 信阳师范华锐学院数学建模选拔赛试题
- socket常用的几个函数
- datagrid数据导出到excel文件给客户端下载的几种方法
- 使用SQL Server维护计划实现数据库定时自动备份
- ACM华锐学院选拔题
- JEXL
- 使用SqlDataAdapter在存储过程中获取记录集填充DataSet
- SQL优化原则
- 在SQL Server中使用种子表生成流水号注意顺序
- S3/S4/S5 Long Run Test