博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Socket
阅读量:4637 次
发布时间:2019-06-09

本文共 2897 字,大约阅读时间需要 9 分钟。

SOCKET WSAAPI socket(
  int af,//协议地址族
  int type,//协议套接字类型
  int protocol//传输层协议
);

Af

Meaning

AF_UNSPEC

0

The address family is unspecified.

AF_INET

2

The Internet Protocol version 4 (IPv4) address family.

AF_NETBIOS

17

The NetBIOS address family. This address family is only supported if a Windows Sockets provider for NetBIOS is installed.

AF_INET6

23

The Internet Protocol version 6 (IPv6) address family.

AF_IRDA

26

The Infrared Data Association (IrDA) address family. This address family is only supported if the computer has an infrared port and driver installed.

AF_BTM

32

The Bluetooth address family. This address family is only supported if a Bluetooth adapter is installed on Windows Server 2003 or later.

 

 

Type

Meaning

SOCK_STREAM

1

Provides sequenced, reliable, two-way, connection-based byte streams with an OOB data transmission mechanism. Uses the Transmission Control Protocol (TCP) for the Internet address family (AF_INET or AF_INET6).

SOCK_DGRAM

2

Supports datagrams, which are connectionless, unreliable buffers of a fixed (typically small) maximum length. Uses the User Datagram Protocol (UDP) for the Internet address family (AF_INET or AF_INET6).

SOCK_RAW

3

Provides a raw socket that allows an application to manipulate the next upper-layer protocol header. To manipulate the IPv4 header, the IP_HDRINCL socket option must be set on the socket. To manipulate the IPv6 header, the IPV6_HDRINCL socket option must be set on the socket.

SOCK_RDM

4

Provides a reliable message datagram. An example of this type is the Pragmatic General Multicast (PGM) multicast protocol implementation in Windows, often referred to as reliable multicast programming.

SOCK_SEQPACKET

5

Provides a pseudo-stream packet based on datagrams.

 

 

protocol

Meaning

IPPROTO_TCP

6

The Transmission Control Protocol (TCP). This is a possible value when the af parameter is AF_INET or AF_INET6 and the type parameter is SOCK_STREAM.

IPPROTO_UDP

17

The User Datagram Protocol (UDP). This is a possible value when the af parameter is AF_INET or AF_INET6 and the type parameter is SOCK_DGRAM.

IPPROTO_RM

113

The PGM protocol for reliable multicast. This is a possible value when the af parameter is AF_INET and the type parameter is SOCK_RDM. On the Windows SDK released for Windows Vista and later, this value is also called IPPROTO_PGM.

 

 

struct sockaddr {
        ushort  sa_family;
        char    sa_data[14];
};
struct sockaddr_in {
        short   sin_family;
        u_short sin_port;
        struct  in_addr sin_addr;//把IP地址保存为4字节数
        char    sin_zero[8];//填充项,使其与sockaddr结构一样长
};

//字节排序:主机对字节编号方式和网络不同

net to host long short

ntohl() ntohs()

htons() htonl()

 

sockaddr_in inter;

int nport=5050;

inter.sin_family=AF_INET;

inter.sin_addr.s_addr=inet_addr("127.0.0.1");

//IP地址→位无符长整形

inter.sin_port=htons(nport);

cout<<inter.sin_port;

转载于:https://www.cnblogs.com/wind-net/archive/2012/07/17/2595535.html

你可能感兴趣的文章
类似以下三图竞争关系的IT企业
查看>>
Qt5启动画面
查看>>
清明节
查看>>
Spring-Cloud-Zuul-网关配置
查看>>
瑞柏匡丞:电商转化率从何而来
查看>>
VMware workstation CentOs 7 虚拟机网卡设置为NAT模式并设置固定IP
查看>>
Philosophy is systematic reflective thinking on life.
查看>>
谈谈一些有趣的CSS题目(七)-- 消失的边界线问题
查看>>
ubuntu如何安装svn客户端?
查看>>
arcgis for javascript (3.17)
查看>>
【MySQL】Win7下修改MySQL5.5默认编码格式
查看>>
AI之路,第二篇:python数学知识2
查看>>
python网络编程:socket套接字
查看>>
SQL serve创建与调用存储过程
查看>>
windows10关闭更新,windowsUpdate禁用无效 windows无限重启 一分钟无限重启 win10无法连接到SENS服务...
查看>>
[LeetCode] Alien Dictionary
查看>>
[LintCode] 空格替换
查看>>
React16 新特性
查看>>
单元测试工具 - karma
查看>>
JSSDK微信支付封装的支付类方法,代码比较齐全,适合收藏
查看>>