I’ve spent the whole day creating a system between my Mac and iPhone where i have used cocoaasyncsocket to create a listen server on my mac and a client on my iPhone. The basic idea is to leave the app on the mac running while the computer is on and then when I wish to transfer data from the iPhone app, fire up the app an it connects and sends the data… I have this system working exactly how I want it to function however I have 1 issue what I have been trying to solve for about 4 hours in total!
I wanted to create something what scans my wireless network for my mac with the listener running… I thought this would be simple, but I was wrong. I have searched high and low with no luck on the case and I am using stackoverflow as my last resort.
My current plan was to “autoscan” by retrieving the internal IP of the iPhone (ie 192.168.1.94) then use that to figure out what the other IP’s on the network will be (192.168.1.0-254), now I know what IP’s to scan i can loop through each one and check to see if the port is open/I get a response.
Now I want to do this as quick as possible however I haven’t been able to get ANYTHING to give me accurate results…
Using connectToAddress:error: in the cocoaasyncsocket will simply just return true for every one of the 255 different IP addresses, so will any other reachability functions that I have come across… I have read that it is because they only check to see if the connection gets made and don’t care about what happens at the other end so I need to think of something else.
My only other solution that I can think of, is to maybe ping each internal IP and see if i get a response but im not sure if this is going to take up too much time having to go through 255 IP addresses… and then, once i get what IP’s are active I still then have to check to see if the port is open somehow :/
If anyone here knows how it can be done or has any better idea how I can check for the open port (i’m not very good with networking) I would be VERY grateful.
Thanks for reading,
Liam
I haven’t worked with it myself but basically Bonjour is actually what you are looking for it’s purpose is publishing and discovery of services