开发者

What are some possible causes of iPhone rejecting UDP packet?

开发者 https://www.devze.com 2022-12-20 22:52 出处:网络
On iPhone, I am running an a开发者_运维问答pp with AsyncUdpSocket library to take care of UDP networking. I have tested it. I can send UDP packet from my iPhone to a server that runs Java program acce

On iPhone, I am running an a开发者_运维问答pp with AsyncUdpSocket library to take care of UDP networking. I have tested it. I can send UDP packet from my iPhone to a server that runs Java program accepting UDP correctly.

However, when it is the other way around, Java program's UDP message doesn't get through to iPhone. So I decided to test the library whether it can send/receive its own UDP packets or not using 127.0.0.1 on iPhone, and the result is it works.

So I was wondering whether the UDP packets are being sent or not, so I used Wireshark to see my network activity.

What are some possible causes of iPhone rejecting UDP packet?

Directlink to image above: http://img46.imageshack.us/img46/7939/screenshot20100220at110.png

In the iPhone program, I instruct my UDP program to connect to 192.168.99.11, which is my MacBook, using port 55555. The Java UDP program on my Macbook is being told that the remote ip to connect to is 192.168.99.13 (my iPhone) on port 55555.

On Wireshark, I can see that ICMP is telling me that the destination and port are unreachable from iPhone.

So does anybody know why iPhone blocks UDP packets? Or is there something I overlook?


Unless I'm missing something in understanding your question you have two client-style applications. Both try to connect to port 55555 on the other host. I have no idea how it works for you on single box.

Let me describe normal client-server (a.k.a active/passive) scenario:

  1. server creates UDP socket and bind(2)s it to known port (55555 in your example),
  2. server calls recv(2)-family function on the socket to accept data from clients,
  3. client creates UDP socket and calls sendto(2) function with destination address argument initialized with servers's IP address and that known port number.
  4. server returns from the recv(2) with the data from client,
  5. optionally client and server exchange more messages.

The key is that you need bound known port on the server side. Server, on the other hand, doesn't need to know address and port of the client, thus server is passive and client(s) is/are active. I should probably add that it's not uncommon for UDP applications to act as both clients and servers at the same time. It's just logically these are separate roles.

That out of the way, there could be a couple of reasons why you get "ICMP port unreachable" response:

  • No process is bound to the port on the server machine (see point 1. above),
  • A firewall on the server machine actively rejects packets sent to that port.

Hope this clears it a bit. Let me know if I grossly misunderstood what you are asking.

0

精彩评论

暂无评论...
验证码 换一张
取 消