C# SIP Registration Gennem UDP
Jeg er igang med at udvikle en softphone og har efterhånden fået læst en del RFC osv...Jeg har denne funktion
[b]
UdpClient udpClient = new UdpClient(5060);
try
{
udpClient.Connect("213.128.137.66", 5060);
// Sends a message to the host to which you have connected.
Byte[] sendBytes = Encoding.ASCII.GetBytes(noAuth);
udpClient.Send(sendBytes, sendBytes.Length);
//IPEndPoint object will allow us to read datagrams sent from any source.
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
// Blocks until a message returns on this socket from a remote host.
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
//... Get nonce here
string nonce = returnData.Substring(returnData.IndexOf("nonce=") + 6).Substring(0, 10).Replace("\"", "").Replace("\"", "");
auth = auth.Replace("6c7da459", nonce);
if (returnData.Contains("401 Unauthorized"))
{
sendBytes = Encoding.ASCII.GetBytes(auth);
udpClient.Send(sendBytes, sendBytes.Length);
receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
returnData = Encoding.ASCII.GetString(receiveBytes);
}
// udpClient.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static string noAuth = "REGISTER sip:213.128.137.66 SIP/2.0\r\n" +
"Via: SIP/2.0/UDP 192.168.1.6:5002;branch=z9hG4bK96148b89-2daf-4802-b4b6-fc78d89d7145;rport\r\n" +
"Max-Forwards: 70\r\n" +
"Contact: <sip:72733182-72733180@192.168.1.6:5002;rinstance=4fa819cc811ffa4a>\r\n" +
"To: \"72733182-72733180\"<sip:72733182-72733180@213.128.137.66>\r\n" +
"From: \"72733182-72733180\"<sip:72733182-72733180@213.128.137.66>;tag=xrifxeyd\r\n" +
"Call-ID: rqmygjcmunmisjxhboxixmqihyldxsrwpuahwlkhkgadijuuir\r\n" +
"CSeq: 1 REGISTER\r\n" +
"User-Agent: Linksys/SPA941-1.8.22\r\n" +
"Content-Length: 0\r\n" +
"Expires: 3600\r\n" +
"Supported: 100rel\r\n" +
"Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, SUBSCRIBE, NOTIFY, REFER, INFO, MESSAGE\r\n\r\n";
public static string auth = "REGISTER sip:213.128.137.66 SIP/2.0\r\n" +
"Via: SIP/2.0/UDP 192.168.1.6:5002;branch=z9hG4bK96148b89-2daf-4802-b4b6-fc78d89d7145;rport\r\n" +
"Max-Forwards: 70\r\n" +
"Contact: <sip:72733182-72733180@192.168.1.6:5002;rinstance=4fa819cc811ffa4a>\r\n" +
"To: \"72733182-72733180\"<sip:72733182-72733180@213.128.137.66>\r\n" +
"From: \"72733182-72733180\"<sip:72733182-72733180@213.128.137.66>;tag=xrifxeyd\r\n" +
"Call-ID: rqmygjcmunmisjxhboxixmqihyldxsrwpuahwlkhkgadijuuir\r\n" +
"CSeq: 2 REGISTER\r\n" +
"User-Agent: Linksys/SPA941-1.8.22\r\n" +
"Content-Length: 0\r\n" +
"Expires: 3600\r\n" +
"Supported: 100rel\r\n" +
"Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, SUBSCRIBE, NOTIFY, REFER, INFO, MESSAGE\r\n" +
"Authorization: Digest username=\"72733182-72733180\",realm=\"mirtapbx\",nonce=\"6c7da459\",response=\"8c5d58be543f09e71156b88220ac69df\",uri=\"sip:213.128.137.66\",algorithm=MD5\r\n\r\n";
[b]
Jeg laver første request uden authentication header > Server sender "challenge" tilbage > Client svare challenge med authentication header.
Mit problem er nu at i stedet for at få det normalle 200OK response for jeg 403 forbidden - Jeg ved godt det betyder, at serveren forstår hvad jeg siger, men ikke vil/kan efterkomme forespørgslen, jeg kan bare ikke se hvad problemet er.
Håber nogle at jer kloge derude kan give et bud, på forhånd tak.