标签:realm try task strip request type ora cancel rds
SIP(Session Initiation Protocol,会话初始协议)是由IETF(Internet Engineering Task Force,因特网工程任务组)制定的多媒体通信协议。广泛应用于CS(Circuit Switched,电路交换)、NGN(Next Generation Network,下一代网络)以及IMS(IP Multimedia Subsystem,IP多媒体子系统)的网络中,可以支持并应用于语音、视频、数据等多媒体业务
,同时也可以应用于Presence(呈现)、Instant Message(即时消息)等特色业务。可以说,有IP网络的地方就有SIP协议的存在。
SIP是类似于HTTP。SIP可以减少应用特别是高级应用的开发时间。由于基于IP协议的SIP利用了IP网络
,固定网运营商也会逐渐认识到SIP技术对于他们的远意义。
主叫方A呼叫被叫方B:
主叫方A
发送INVITE请求到代理服务器
;代理服务器
发送100 Trying 响应主叫方A
;代理服务器
搜索被叫方B
的地址,获取地址后转发INVITE请求;被叫方B
生成的180 振铃响应,返回给主叫方A
;被叫方B
生成的200 OK响应,返回给主叫方A
;主叫方A
收到被叫方B
200 OK响应后,向被叫方B
发送一个ACK,会话建立;主叫方A
发送200 OK响应来确认BYE,会话终止。SIP消息与Http
相似,其由三部分组成:
请求行格式:Method Request-URI SIP-Version CRLF
请求行举例:INVITE sip:bob@zte.com SIP/2.0 /r/n
Method
以下列出了六种消息Method方法
:
Method | 方法说明 |
---|---|
REGISTER | 注册联系信息 |
INVITE | 发起会话请求 |
ACK | INVITE 请求的响应的确认 |
CANCEL | 取消请求 |
BYE | 终结会话 |
OPTIONS | 查询服务器能力 |
Request-URI
指示请求的用户或者服务的地址信息
SIP-Version
请求和响应消息都需要包含SIP版本信息
状态行格式: SIP-Version Status-Code Reason-Phrase CRLF
状态行举例:SIP/2.0 200 OK /r/n
Status-Code状态码:
状态代码由3位数字组成,表示请求是否被理解或被满足。
状态代码的第一个数字定义了响应的类别,后面两位没有具体的分类
。
第一个数字有五种可能的取值:
状态码 | 含义 |
---|---|
1xx: | 临时响应、表示请求消息正在被处理 |
2xx | 成功响应、表示请求已被成功接收完全理解并接收 |
3xx | 重定向响应、表示需采取进一步完成请求 |
4xx | 客户机错误、表示请求消息中包含语法错误信息或服务器无法完成客户机的请求 |
5xx | 服务器错误、表示服务器无法合法完成请求 |
6xx | 全局故障 、表示任何服务器都无法完成该请求 |
常用的状态码举例:
状态码 | msg | 含义 |
---|---|---|
100 | Trying | 试呼叫 |
180 | Ringing | 振铃 |
181 | Call is Being Forwarded | 呼叫正在前转 |
200 | OK | 成功响应 |
302 | Moved Temporarily | 临时迁移 |
400 | Bad Request | 错误请求 |
401 | Unauthorized | 未授权 |
403 | Forbidden | 禁止 |
404 | Not Found | 用户不存在 |
408 | Request Timeout | 请求超时 |
480 | Temporarily Unavailable | 暂时无人接听 |
486 | Busy Here | 线路忙 |
504 | Server Time-out | 服务器超时 |
600 | Busy Everywhere | 全忙 |
发送MESSAGE请求消息给192.168.100.02的2222端口
MESSAGE sip:1897778888@192.168.100.02:2222 SIP/2.0
Call-ID: 8e12c17121ac4121bf927f6fd8013358@192.168.100.1
From: <sip:01052237300@192.168.100.1>;tag=-0037-708c9a5cba8dd878
To: <sip:1897778888@192.168.100.1>
CSeq: 1 MESSAGE
Via: SIP/2.0/UDP 192.168.100.1:1111;branch=z9hG4bK--22bd7222
Max-Forwards: 30
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,REGISTER,INFO,UPDATE,PRACK,REFER,SUBSCRIBE,NOTIFY,MESSAGE
Contact: <sip:192.168.100.1:1111>
Content-Type: text/plain
Content-Length: 5
Hello
Header | 含义说明 | 举例 |
---|---|---|
Call-ID | 由本地设备(Client)生成,全局唯一,每次呼叫这个值唯一不变 | Call-ID: 8e12c17121ac4121bf927f6fd8013358@192.168.100.1 |
From | 表示请求的发起者 | From: sip:01052237300@192.168.100.1;tag=-0037-708c9a5cba8dd878 |
To | 表示请求的接收者 | To: sip:1897778888@192.168.100.1 |
Via | Via头域是被服务器插入request中,用来检查路由环的,并且可以使response根据via找到返回的路 | Via: SIP/2.0/UDP 192.168.100.1:1111;branch=z9hG4bK--22bd7222 |
Max-Forwards | 用于表示这个包最多可以传送多少跳,每经过一跳都会减一当Max-Forwards==0系统会返回483。默认为70 | Max-Forwards: 30 |
Contact | 包含源的URI信息,用来给响应方直接和源建立连接用 | Contact: sip:192.168.100.1:1111 |
Content-Type | 指明消息体的类型 (SDP会话描述协议) | Content-Type: text/plain;Content-Type: application/sdp |
Content-Length | 指明消息体的字节大小 | Content-Length: 5 |
这里举两个例子:
发送MESSAGE请求消息给192.168.100.02的2222端口:
MESSAGE sip:1897778888@192.168.100.02:6010 SIP/2.0
Call-ID: 8e12c17121ac4121bf927f6fd8013358@192.168.100.1
From: <sip:01052237300@192.168.100.1>;tag=-0037-708c9a5cba8dd878
To: <sip:1897778888@192.168.100.1>
CSeq: 1 MESSAGE
Via: SIP/2.0/UDP 192.168.100.1:1111;branch=z9hG4bK--22bd7222
Max-Forwards: 30
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,REGISTER,INFO,UPDATE,PRACK,REFER,SUBSCRIBE,NOTIFY,MESSAGE
Contact: <sip:192.168.100.1:1111>
Content-Type: text/plain
Content-Length: 5
Hello
收到来自192.168.100.02的2222端口的返回消息:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.100.1:1111;branch=z9hG4bK--22bd7222
From: <sip:01052237300@192.168.100.1>;tag=-0037-708c9a5cba8dd878
To: <sip:1897778888@192.168.100.1>;tag=-002-3c18e810ab17c76f
Call-ID: 8e12c17121ac4121bf927f6fd8013358@192.168.100.1
CSeq: 1 MESSAGE
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,REGISTER,INFO,UPDATE,PRACK,REFER,SUBSCRIBE,NOTIFY,MESSAGE
Contact: <sip:192.168.100.02:54010>
Content-Type: text/plain
Content-Length: 11
Hello Hello
192.168.2.161
机器发送注册消息给192.168.2.89
服务器:
REGISTER sip:192.168.2.89 SIP/2.0
Via: SIP/2.0/UDP 192.168.2.161:10586
Max-Forwards: 70
From: <sip:01062237496@192.168.2.89>;tag=ca04c1391af3429491f2c4dfbe5e1b2e;epid=4f2e395931
To: <sip:01062237496@192.168.2.89>
Call-ID: da56b0fab5c54398b16c0d9f9c0ffcf2@192.168.2.161
CSeq: 1 REGISTER
Contact: <sip:192.168.2.161:10586>;methods="INVITE, MESSAGE, INFO, SUBSCRIBE, OPTIONS, BYE, CANCEL, NOTIFY, ACK, REFER"
User-Agent: RTC/1.2.4949 (BOL SIP Phone 1005)
Event: registration
Allow-Events: presence
Content-Length: 0
当注册成功(回送200 OK)时,服务器发送的res消息参考如下:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.2.161:10586
From: <sip:01062237496@192.168.2.89>;tag=ca04c1391af3429491f2c4dfbe5e1b2e;epid=4f2e395931
To: <sip:01062237496@192.168.2.89>;tag=-00834-14d0805b62bc026d
Call-ID: da56b0fab5c54398b16c0d9f9c0ffcf2@192.168.2.161
CSeq: 1 REGISTER
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,REGISTER,INFO,UPDATE,PRACK,REFER,SUBSCRIBE,NOTIFY,MESSAGE
Contact: sip:192.168.2.161:10586
Content-Length: 0
Expires: 3600
当需要鉴权注册时
请求端192.168.2.161
发送注册消息给192.168.2.89
服务器
REGISTER sip:192.168.2.89 SIP/2.0
Via: SIP/2.0/UDP 192.168.2.161:8021
Max-Forwards: 70
From: <sip:01062237493@192.168.2.89>;tag=efca469543ce4788a6a6a2c7b66cd01f;epid=de4504430d
To: <sip:01062237493@192.168.2.89>
Call-ID: c88a247a74b54a8c9e676bdde3bba6c9@192.168.2.161
CSeq: 1 REGISTER
Contact: <sip:192.168.2.161:8021>;methods="INVITE, MESSAGE, INFO, SUBSCRIBE, OPTIONS, BYE, CANCEL, NOTIFY, ACK, REFER"
User-Agent: RTC/1.2.4949 (BOL SIP Phone 1005)
Event: registration
Allow-Events: presence
Content-Length: 0
服务器对192.168.2.161
发送401 Unauthorized
信息给请求端,提示请求端需要带上鉴权信息重新注册:
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.2.161:8021
From: <sip:01062237493@192.168.2.89>;tag=efca469543ce4788a6a6a2c7b66cd01f;epid=de4504430d
To: <sip:01062237493@192.168.2.89>;tag=-001893-38ba013ba3dde36e
Call-ID: c88a247a74b54a8c9e676bdde3bba6c9@192.168.2.161
CSeq: 1 REGISTER
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,REGISTER,INFO,UPDATE,PRACK,REFER,SUBSCRIBE,NOTIFY,MESSAGE
Contact: <sip:192.168.2.89:14010>
Content-Length: 0
WWW-Authenticate: Digest realm="192.168.2.89", qop="auth", nonce="e17d377c3d2d9c343e26576a7fd04738481dfc10", opaque="", stale=FALSE, algorithm=MD5
请求端192.168.2.161
通过Authorization
头字段带上鉴权头信息,发送一个新的REGISTER消息:
REGISTER sip:192.168.2.89 SIP/2.0
Via: SIP/2.0/UDP 192.168.2.161:8021
Max-Forwards: 70
From: <sip:01062237493@192.168.2.89>;tag=efca469543ce4788a6a6a2c7b66cd01f;epid=de4504430d
To: <sip:01062237493@192.168.2.89>
Call-ID: c88a247a74b54a8c9e676bdde3bba6c9@192.168.2.161
CSeq: 2 REGISTER
Contact: <sip:192.168.2.161:8021>;methods="INVITE, MESSAGE, INFO, SUBSCRIBE, OPTIONS, BYE, CANCEL, NOTIFY, ACK, REFER"
User-Agent: RTC/1.2.4949 (BOL SIP Phone 1005)
Authorization: Digest username="01062237493", realm="192.168.2.89", qop=auth, algorithm=MD5, uri="sip:192.168.2.89", nonce="e17d377c3d2d9c343e26576a7fd04738481dfc10", nc=00000001, cnonce="12660455546344082314666316435946", response="f57e47ce03162293b9ced07362ce2b79"
Event: registration
Allow-Events: presence
Content-Length: 0
服务器验证鉴权头的正确性,如果鉴权成功,给请求端发送200 OK消息。若失败,继续发送401消息
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.2.161:8021
From: <sip:01062237493@192.168.2.89>;tag=efca469543ce4788a6a6a2c7b66cd01f;epid=de4504430d
To: <sip:01062237493@192.168.2.89>;tag=-001894-a5eb977c8969aa51
Call-ID: c88a247a74b54a8c9e676bdde3bba6c9@192.168.2.161
CSeq: 2 REGISTER
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,REGISTER,INFO,UPDATE,PRACK,REFER,SUBSCRIBE,NOTIFY,MESSAGE
Contact: sip:192.168.2.161:8021
Content-Length: 0
Expires: 3600
SIP协议中MESSAGE消息的扩展使得SIP能够支持IM通信。
MESSAGE消息的消息体可以是任何MIME类型的消息体,包括message/cpim(见RFC3860)格式
CPIM消息格式
https://www.xuebuyuan.com/1929719.html
标签:realm try task strip request type ora cancel rds
原文地址:https://www.cnblogs.com/xiaxveliang/p/12411890.html