2017-02-07 73 views
0

我試圖做簡單的click-to-call app。我安裝了星號服務器,我可以使用免費撥打電話。但是當我使用我的應用發送內容時,我沒有得到任何迴應。Asterisk沒有通過SIP響應應用請求

我之前沒有使用套接字。所以,情況可能如此。

這裏是我的代碼:

string registerHeader = "REGISTER sip:asteriskip;transport=UDP SIP/2.0\r\n"; 
string toHeader = "To: <sip:[email protected];transport=UDP>\r\n"; 
string fromHeader = "From: <sip:[email protected];transport=UDP>\r\n"; 
string callId = "Call-ID: 1\r\n"; 
string CSeq = "CSeq: 1 REGISTER\r\n"; 
string expires = "Expires: 3600\r\n"; 
string via = "Via: SIP/2.0/UDP myip:myport;branch=z9hG4bK-1\r\n"; 
string maxF = "Max-Forwards: 70\r\n"; 
string UA = "User-Agent: MySoftphone\r\n"; 
string contact = "Contact: <sip:[email protected]:myport;transport=UDP>\r\n"; 
string contLength = "Content-Length: 0\r\n\r\n"; 

Socket cl = new Socket(SocketType.Dgram, ProtocolType.Udp); 
byte[] registerMsg = Encoding.ASCII.GetBytes(registerHeader + toHeader + 
    fromHeader + callId + CSeq + expires+via+maxF+UA+contact+contLength); 
IPEndPoint server = new IPEndPoint(IPAddress.Parse("asteriskip"), 5060); 
cl.Connect(server); 
cl.Send(registerMsg);//(registerMsg, registerMsg.Length); 
int bytesCount = 0; 
do 
{ 
    byte[] response = new byte[] { }; 
    cl.Receive(response);//(ref server); 
    bytesCount = response.Length; 
    string resp = Encoding.ASCII.GetString(response); 
    Console.WriteLine(resp); 
} 
while (bytesCount == 0); 
Console.ReadKey(); 

這個請求是幾乎相同softphone's,把它從wireshark。但獲得響應,並且此請求不。應該有註冊CSeq 2,我試圖發送它 - 仍然沒有,如果我沒有弄錯,我應該收到類似401-Unauthorized註冊後的第一部分。

回答

0

經過一番研究,我發現我缺少tag參數。如果沒有設置tag,服務器將忽略請求。