1
votes

I can send a udp message to specific url and port (successfully) but I can't receive response message that I can see on Wireshark!

This is the code that I use for udp connection:

Byte[] sendBytes = Encoding.ASCII.GetBytes(sipMessage);
String responseData = String.Empty;
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

try
{
    using (UdpClient udpClient = new UdpClient(ipaddr, 5060))
    {
        udpClient.Client.ReceiveTimeout = 1000;
        udpClient.Send(sendBytes, sendBytes.Length);
        Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
        responseData = Encoding.ASCII.GetString(receiveBytes);
    }
}
catch (Exception ex)
{
    responseData = ex.Message;
}

If I don't set timeout, thread keeps working.

The response message is:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

The result from wireshark is below:

+-----+-----------+--------------+--------------+----------+--------+--------------------------------------------------------+
| No. |   Time    |    Source    | Destination  | Protocol | Length |                          Info                          |
+-----+-----------+--------------+--------------+----------+--------+--------------------------------------------------------+
| 465 | 33.378167 | 192.168.1.61 | 192.168.1.63 | SIP      |    289 | Request: MESSAGE sip:[email protected] |  (text/plain) |
| 469 | 33.817460 | 192.168.1.63 | 192.168.1.61 | SIP      |    254 | Status: 200 OK |                                       |
+-----+-----------+--------------+--------------+----------+--------+--------------------------------------------------------+

addendum: 192.168.1.61 is a computer that hosts a web page, 192.168.1.63 is a wifi dect phone

I need to send a sip message to the wifi dect (which I already achieved)

phone sends back a sip message to 192.168.1.61:5060. SIP flow is like:

[Random Port] -- Message --> [5060]

[5060] <-- 200 OK -- [5060]

so, pc connect to dect as a udp client and sends message, dect sends back 200 OK sip message to pc's 5060 port. I have problem on receiving 200 OK message!

NEWS: When I stop pbx server's services, I can get the result (200 OK); otherwise, I'm not able to receive any sip message...

2

2 Answers

0
votes

The UDP protocol does not work like that. It's one-way only. It does not verify the listening party is ready to receive, not does it give any response about succesful delivery of the data.

If you want feedback, try using TCP.

0
votes

When you create your UDP Socket like this new UdpClient(ipaddr, 5060) you bind it to any available local port, and connect it to remote server with IP ipaddr and port 5060. So when you send something over this socket, it reaches the server.

However, this socket will not see SIP replies from the server. Server is going to send SIP reply message to 5060 (or 5061 for encrypted SIP). But you are not listening on this part (in fact, nobody is, so kernel just drops this datagram). To properly receive those messages, you need to bind your local udp socket to SIP port as well.