I have a networked game I'm testing on a LAN. I'm using RakNet as my networking library.
Generally everything works fine, but sometimes the client (an iPhone) seems to get "confused" when initiating a connection to the server (a Macbook on the same LAN -- both connected wirelessly).
Once the client has connected, everything works fine. It will maintain the connection indefinitely. But sometimes the call to connect()
just sits and spins and never seems to get anywhere, even after about 30 seconds. I will start receiving "No route to host" and "Host is down" messages on the client side.
What I've found is that, during this waiting period that won't resolve itself, if I initiate a ping from the server (the Macbook) to the client (the iPhone), immediately the client will connect. It could be 28 seconds into waiting and as soon as I try to ping it everything resolves.
During periods where the connection is acting up, I've also found that trying to ping from the iPhone to the Macbook doesn't work.
Does this sound like some kind of router issue? It's really intermittent -- things will work just fine for a few minutes and then I can repeatedly reproduce the inability to connect. Then I ping the client and everything is working again.
It's incredibly frustrating and I'd love some guidance about what may be causing the issues!
UPDATE 1
@PedroPerez commented that this may be related to an ARP issue. To try to get some data on this, I ran the following tests in promiscuous mode and tried to find ARP packets to look at:
- WireShark running on Macbook (server)
- WireShark running on iPhone (client)
When capturing data on the server, I found that every 20-50 seconds, I would see a pair of ARP calls with the router requesting the MAC address of the server's IP followed by an immediate response. Every 70 seconds, my Macbook (the server) would request the MAC address of my Apple TV. That was it for the "steady state" ARP traffic on the server. It would repeat itself like clockwork. Here's a screenshot:
When capturing data through the virtual interface on the client (which I created through a call to rvictl
in the terminal), the picture was a bit more muddy. First of all, for some reason the ARP packets were not coming through to WireShark as ARP packets, even though the contents appeared to be the same (42 bytes). They just appeared as "Raw packet data". By examining the contents of the raw packets, I could see that every five seconds (seems excessive?!) the iPhone (client) was receiving an ARP reply packet (seemingly unsolicited?) from the router giving it stating its correct IP address. I'm not sure why the frequency is so high or why the router seems to be sending replies without requests. Here's a screenshot of that process.
I've also managed to capture ARP packets during this extraordinarily long timeout period and noticed that just before the connection succeeds (after waiting around for 20-30s), one of the (likely 'steady-state') broadcast packets goes out from the Macbook requesting the (completely unrelated!) MAC address of the Apple TV. However, the broadcasted request from the Macbook includes both its IP and MAC address, so perhaps since the iPhone client is able to "hear" that broadcasted request it updates its ARP table as soon as it sees that request? But then why is it forgetting it again?