如何通过SIP发送即时消息 [英] How to send instant message via SIP

查看:161
本文介绍了如何通过SIP发送即时消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由移动网络提供商制作的Windows桌面应用程序,它使用SIP进行各种操作:呼叫,发送消息等.此应用程序如何成功发送MESSAGE的屏幕截图(最后4行) :

I have a windows desktop application, made by my mobile network provider, that does all kind of things with SIP: call, send message, etc. Screenshot of how does this app successfully send MESSAGE (the last 4 lines):

MESSAGE请求发送为(后面的第4行):

MESSAGE request, from desktop application, is sent as (4th line from behind) :

MESSAGE sip:FROM@DOMAIN SIP/2.0
Via: SIP/2.0/UDP LOCALIP:2112;branch=z9hG4bK-d8754z-905183245f478c76-1---d8754z-;rport
Max-Forwards: 70
To: "TO"<sip:TO@DOMAIN>
From: "FROM"<sip:USERNAME@DOMAIN>;tag=63088d09
Call-ID: NGVhMDJhYzQwNmExOTQyNThmNjc5OGNmOTViNDUyYWM.
CSeq: 2 MESSAGE
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
Content-Type: text/plain
Content-Length: 4

test

对此的成功响应是:

SIP/2.0 407 Proxy Authentication Required
Via: SIP/2.0/UDP LOCALIP:2112;received=EXTERNALIP;branch=z9hG4bK-d8754z-905183245f478c76-1---d8754z-;rport=2112
To: "TO"<sip:TO@DOMAIN>;tag=c005f0e30133ec730add76fc91f4bea
From: "FROM"<sip:USERNAME@DOMAIN>;tag=63088d09
Call-ID: NGVhMDJhYzQwNmExOTQyNThmNjc5OGNmOTViNDUyYWM.
CSeq: 2 MESSAGE
Content-Length: 0
Proxy-Authenticate: Digest nonce="3F178051B97E1F52000123000A3C53D4B",realm="DOMAIN",algorithm=MD5,qop="auth"

然后我尝试从PHP发送相同的(和n个变化)请求,但是我总是收到SIP/2.0 403 Forbidden而不是SIP/2.0 407 Proxy Authentication Required:

Then I try to send identical (and n-variations) request from PHP, but I always receive SIP/2.0 403 Forbidden instead of SIP/2.0 407 Proxy Authentication Required:

SIP/2.0 403 Forbidden
Via: SIP/2.0/UDP LOCALIP;received=EXTERNALIP
To: "TO"<sip:TO@DOMAIN>;tag=aprqngfrt-f7ccjj0000020
From: "FROM"<sip:USERNAME@DOMAIN>;tag=8f7be81d
Call-ID: 526576901edcc@localhost
CSeq: 1 MESSAGE
Reason: Q.850;cause=55;text="Call Terminated"
Content-Length: 0

有趣的部分是,如果我发送REGISTER请求,则该请求有效,并且我成功接收到带有WWW-AuthenticateSIP/2.0 401 Unauthorized标头.我重新计算授权,然后重新发送.然后我收到SIP/2.0 200 OK.它应该与MESSAGE一起使用.

The funny part is, that if I send REGISTER request it works, and I successfully receive SIP/2.0 401 Unauthorized header with WWW-Authenticate. I recalculate authorization, and resend it. Then I receive SIP/2.0 200 OK. Which is how it should work with MESSAGE.

可能是什么问题?我错过了什么? MESSAGE请求在此之前是否需要其他请求(我之前已经尝试过REGISTER)?
我已阅读

What could be wrong? What did I miss? Does MESSAGE request need some other request before that (I have already tried REGISTER before)?
I have read RFC 3428 up and down, tried all the examples possible, but without success.

推荐答案

如果查看收到的403响应,您会注意到Reason标头.开头的Q.850字符串表示这将是ITU-T建议书定义的原因码.

If you look into received 403 response, you'll notice a Reason header. The Q.850 string at the beginning indicates that this would be a cause code defined by ITU-T Recomendation.

具体来说,提供的原因代码55与ISDN有关,并且文学手段是封闭用户组中禁止传入的呼叫"(您可以在 RFC 3398 ),通常意味着在一组成员中,呼叫接收受到限制.

Specifically, provided cause code 55 is related to ISDN and literary means "Incoming calls barred within Closed User Group" (you can check it in RFC 3398) and, usually, means that, within a group of members, call reception is restricted.

另一方面,原因55也表示请求中的问题,特别是与用户(发送者或接收者)有关的问题.下图显示了SIP用户之间的正常MESSAGE交换:

On the other hand, cause 55 also denotes a problem within the request, specially in relation to a user (sender or receiver). Following diagram shows a normal MESSAGE exchange between SIP users:

      A             Server             B
      |    REGISTER    |               |
      |--------------->|               |
      |     200 OK     |               |
      |<---------------|               |
      |                |    REGISTER   |
      |                |<--------------|          
      |                |     200 OK    |
      |                |-------------->|
      |    MESSAGE     |               |
      |--------------->|    MESSAGE    |
      |                |-------------->|
      |                |     200 OK    |
      |                |<--------------|
      |     200 OK     |               |
      |<---------------|               |

实际上,严格地说,不需要来自用户A的注册,但是大多数系统(如IMS)都将其用作身份验证机制.然后,在REGISTER请求中,特殊的标头是:

Actually, been strict, REGISTER from user A is not needed but most systems (like IMS) uses it as an authentication mechanism. Then, in REGISTER request, special headers are:

Contact: <sip:USER_NAME@LOCAL_IP:LOCAL_PORT>
Expires: REGISTRATION_DURATION

请记住,一个200 OK的REGISTER答案可以在Contact:标头中包含一个Expires:标头或一个expires参数,该参数指示可接受的到期时间.例如:

Keep in mind that, 200 OK answers to a REGISTER, can contain an Expires: header or an expires parameter inside Contact: header that indicates accepted expiration time. For example:

SIP/2.0 200 OK
...
Contact: <sip:USER_NAME@LOCAL_IP:LOCAL_PORT>; expires=60 
...

在这种情况下,您应该在此到期时间(示例中为60秒)之前重新注册.

In this situation, you should re-REGISTER before this expiration time (60 seconds in the example).

请记住,您正在尝试将SMS发送到手机,接收点由网络提供商的 MGCF ,因此这将保留发件人的注册或MESSAGE请求.

Keeping in mind that you're trying to send an SMS to a mobile phone, reception point is directly managed by your network provider's MGCF, so this leaves sender's registration or MESSAGE request.

关于您原始的MESSAGE提案,请求URI(消息的第一行)应为:

About your original MESSAGE proposal, request URI (message's first line), should be:

 MESSAGE sip:TO@DOMAIN SIP/2.0

因为它是指MESSAGE接收实体.

Because it refers to MESSAGE reception entity.

希望这会有所帮助.

这篇关于如何通过SIP发送即时消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆