# Sip协议(三)- 通话接听流程
本文主要记录下sip通信下接听的流程.
### 一: 接听流程
1. agent接听电话
2. 远端在未接听情况下主动挂断电话.
接听流程涉及到的请求有: INVITE,CANCEL,ACK,BYE
具体的过程如下:
### 二: sip过程
1. agent收到INVITE
```
INVITE sip:1000@10.0.0.1:10000;transport=tcp SIP/2.0
Via: SIP/2.0/TCP 10.0.0.1:5060;branch=z9hG4bKxxxx;rport=5060
Route: <sip:1000@124.64.0.1:10988>;transport=tcp
Max-Forwards: 70
From: "Extension 1001" <sip:1001@172.17.0.1>;tag=Q79QQcg41UBpe
To: <sip:1000@10.0.0.1:10000;transport=tcp>
Call-ID: e040d830-a8aa-123d-0a8e-11111111111b
CSeq: 84836083 INVITE
Contact: <sip:mod_sofia@10.0.0.1:5060;transport=tcp>
User-Agent: FreeSWITCH-mod_sofia/1.10.10-release~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: path, replaces
Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 426
X-voice_call_number: 18300000000
X-empolyee_id: 1001
X-FS-Support: update_display,send_info
Remote-Party-ID: "Extension 1001" <sip:1001@172.17.0.1>;party=calling;screen=yes;privacy=off
v=0
o=FreeSWITCH 1718762975 1718762976 IN IP4 10.0.0.1
s=FreeSWITCH
c=IN IP4 10.0.0.1
t=0 0
m=audio 16776 RTP/AVP 9 0 8 101
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20
m=video 16862 RTP/AVP 102
b=AS:3072
a=rtpmap:102 VP8/90000
a=rtcp-fb:102 ccm fir
a=rtcp-fb:102 ccm tmmbr
a=rtcp-fb:102 nack
a=rtcp-fb:102 nack pli
```
2. agent发起 Trying 100
```
SIP/2.0 100 Trying
Via: SIP/2.0/TCP 10.0.0.1:5060;branch=z9hG4bK1111;rport=5060
To: <sip:1000@10.0.0.1:10000;transport=tcp>
From: "Extension 1001" <sip:1001@172.17.0.1>;tag=027KZHpcBFDXH
Call-ID: 42ed1f48-a8ac-123d-0a8e-11111111111a
CSeq: 84836381 INVITE
Server: AgentTest/1.0.0/V2318A
Content-Length: 0
```
3. agent发起请求 Ringing 180
180: 振铃中.
```
SIP/2.0 180 Ringing
Via: SIP/2.0/TCP 10.0.0.1:5060;branch=z9hG4bKgvtvc29HgQZ5e;rport=5060
To: <sip:1000@10.0.0.1:10000;transport=tcp>;tag=ec6c9cb5b93df28e
From: "Extension 1001" <sip:1001@172.17.0.1>;tag=027KZHpcBFDXH
Call-ID: 42ed1f48-a8ac-123d-0a8e-11111111111a
CSeq: 84836381 INVITE
Server: AgentTest/1.0.0/V2318A
Content-Length: 204
Content-Type: application/sdp
v=0
o=1000@10.0.0.1 0 0 IN IP4 10.239.19.29
s=Session SIP/SDP
c=IN IP4 10.239.19.29
t=0 0
m=audio 21000 RTP/AVP 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
```
4. agent接收到CANCEL请求
```
CANCEL sip:1000@10.0.0.1:10000;transport=tcp SIP/2.0
Via: SIP/2.0/TCP 10.0.0.1:5060;branch=z9hG4bKgvtvc29HgQZ5e;rport=5060
Route: <sip:1000@124.64.22.13:10988>;transport=tcp
Max-Forwards: 70
From: "Extension 1001" <sip:1001@172.17.0.1>;tag=027KZHpcBFDXH
To: <sip:1000@10.0.0.1:10000;transport=tcp>
Call-ID: 42ed1f48-a8ac-123d-0a8e-11111111111a
CSeq: 84836381 CANCEL
Reason: SIP;cause=487;text="ORIGINATOR_CANCEL"
Content-Length: 0
```
5. agent回执 200
```
SIP/2.0 200 OK
Via: SIP/2.0/TCP 10.0.0.1:5060;branch=z9hG4bKgvtvc29HgQZ5e;rport=5060
To: <sip:1000@10.0.0.1:10000;transport=tcp>
From: "Extension 1001" <sip:1001@172.17.0.1>;tag=027KZHpcBFDXH
Call-ID: 42ed1f48-a8ac-123d-0a8e-11111111111a
CSeq: 84836381 CANCEL
Server: AgentTest/1.0.0/V2318A
Content-Length: 0
```
6. agent回执487
487: Request Terminated 请求被BYE或者CANCEL所终止.
```
SIP/2.0 487 Request Terminated
Via: SIP/2.0/TCP 10.0.0.1:5060;branch=z9hG4bKgvtvc29HgQZ5e;rport=5060
To: <sip:1000@10.0.0.1:10000;transport=tcp>
From: "Extension 1001" <sip:1001@172.17.0.1>;tag=027KZHpcBFDXH
Call-ID: 42ed1f48-a8ac-123d-0a8e-11111111111a
CSeq: 84836381 INVITE
Server: AgentTest/1.0.0/V2318A
Content-Length: 0
```