SIP协议之 格式定义

前言

本章主要说明, SIP协议格式的定义


1、格式定义, 参考RFC3261

   A SIP message is either a request from a client to a server, or a
   response from a server to a client.

   Both Request (section 7.1) and Response (section 7.2) messages use
   the basic format of RFC 2822 [3], even though the syntax differs in
   character set and syntax specifics.  (SIP allows header fields that
   would not be valid RFC 2822 header fields, for example.)  Both types
   of messages consist of a start-line, one or more header fields, an
   empty line indicating the end of the header fields, and an optional
   message-body.

         generic-message  =  start-line
                             *message-header
                             CRLF
                             [ message-body ]
         start-line       =  Request-Line / Status-Line

   The start-line, each message-header line, and the empty line MUST be
   terminated by a carriage-return line-feed sequence (CRLF).  Note that
   the empty line MUST be present even if the message-body is not.

   Except for the above difference in character sets, much of SIP's
   message and header field syntax is identical to HTTP/1.1.  Rather
   than repeating the syntax and semantics here, we use [HX.Y] to refer
   to Section X.Y of the current HTTP/1.1 specification (RFC 2616 [8]).

   However, SIP is not an extension of HTTP.

2、通俗解释, 大致如下

INVITE sip:[email protected]:5061;transport=tls SIP/2.0\r\n
Via: SIP/2.0/TLS 47.92.11.36:5061;branch=z9hG4bKa194b86b95f30823z;rport\r\n
Via: SIP/2.0/TLS 192.168.1.158:52065;branch=z9hG4bKa194b86b95f30823;rport\r\n
Contact: \r\n
Max-Forwards: 70\r\n
To: \r\n
From: ;tag=ee1f8d5638b79986\r\n
Call-ID: 2c09029b27c11eff\r\n
CSeq: 4739 INVITE\r\n
User-Agent: 1.0.2\r\n
Allow: INVITE,ACK,BYE,CANCEL,OPTIONS,REFER,NOTIFY,SUBSCRIBE,INFO,MESSAGE\r\n
Content-Type: application/sdp\r\n
Content-Length: 479\r\n
Record-Route: \r\n
\r\n
v=0
o=- 1488844142 947269169 IN IP4 47.92.145.248
s=-
c=IN IP4 47.92.145.248
t=0 0
a=tool:baresip
m=audio 51084 RTP/AVP 0 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=rtpmap:8 PCMA/8000
a=sendrecv
a=ptime:20
a=label:1
a=rtcp-rsize
m=video 51086 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=42e029
a=sendrecv
a=label:2
a=rtcp-rsize
a=RUDT:287454020
a=rtcp-fb:* nack pli
a=content:main

  • 头域每行结尾以"\r\n"
  • 头域最后一行以"\r\n\r\n"

你可能感兴趣的:(sip)