IphoneOS sockets example - iphone

I am trying to get a simple sockets program working on the Ipad.
To do this I am using the CFStreamCreatePairWithSocketToHost command.
It works fine on the simulator.
The problem is that it does not work on the iPad (I checked connectivity issues using the iPad's safari, and everything seems fine).
What I want to do is have the iPad open a connection to a PC. The reason I used CFStreamCreatePairWithSocketToHost was that I found a simple 10 line sample program which does this.
My questions:
1 - Does CFStreamCreatePairWithSocketToHost work on the iPad
2 - Can anyone direct me to a simple sample for ipad socket communications (I tried apple dev, and google. No sample that I found could be considered simple (less than 50 lines of code...))
Update:
Also tried sockets and NSHost, both withAddress and withName.
The results were the same: works perfectly inside the simulator, but does not work on the iPad.

I would suggest to use the socket-wrapper AsyncSocket. The download comes with a sample project.
edit
the most recent version can be found here

The low level APIs don't turn on the cellular radios. Use a very high level API to connect, then after the radios are turned on, disconnect if necessary, and (re)connect via BSD sockets.
An HTTP request to a server near the same destination IP would probably be sufficient.

Found the problem...
There was a "rouge" proxy problem in my organization, which was forwarding the saffari, but not my program (even thoughthe safati was not on an http port).
Solved, and thanks for your help.

Related

iPhone simulator writes to socket fine - but not iPhone

Despite working earlier, my socket chat app now refuses to write to socket on the iPhone!
It works fine on the simulator and again, used to run fine on my phone. I don't really know where to start troubleshooting this issue --- just seems weird. My server doesn't detect anything trying to connect.
Any ideas on how to start troubleshooting this?
Thanks tons.
I did run into a problem where using sockets on the iPhone would not open up the cell phone network unless something else opened it first. I had to run an http call to a generic web site first, and then the sockets would communicate normally. Try putting a call, like sendSynchronousRequest, to a generic web site, like www.apple.com, before opening your socket, and see if it works in that case.
I need to stop wasting all you nice peoples' time.
Long story, my friend updated to iOS 5.1. Now the 3G network reads 4G on iOS 5.1. So I turned off my (5.0) wifi to see if mine cell network was "4G" (which, of course, it wasn't).
But yeah, having turned off wifi my app could no longer join my locally hosted server...
I grabbed Charles though, and it looks handy, so thanks for that anyways. Also Owen's comment about the cell network originally made me think about checking my wifi, as my app shouldn't even be using the cell network yet. But I'll keep in mind what you said for the future.
Thanks everybody!

Establish Socket connection between window and iPad

I need to establish socket connection between window machine and iPads. So here window machine is a sever which can connect to one or many iPad. For window machine(server) code is already there.
So will it be any issue while connecting window machine with iPads using socket?? and what is the best way to do it ?
If you're asking for possible issues because one side is Win and the other iOS then you can be sure that's not gonna cause any issues.
Assuming you're talking about iOS TCP client - one good tutorial is here: iPhone Network Programming.
There is also Robbie Hanson's CocoaAsyncSocket: well written, easy to implement and comes with examples. Examples are OSX projects but can be quickly converted to iOS projects.

iOS / Mac Bonjour service not found on network

I have an iOS app that publishes a Bonjour service. On my network, the Mac app recognizes the service and everything runs smoothly. On some networks however, the Bonjour service is not "seen" by the Mac. I can't reproduce this on my own network. I have had users check for the service using Bonjour Browser and it's not found. Is there a way to diagnose this problem further? I thought it might be a firewall / router issue but some users have very simple Apple-based networks (Airport). Any ideas on what could be causing this?
Have you tried implementing the
- (void)netService:(NSNetService *)sender didNotPublish:(NSDictionary *)errorDict
method? it can occasionally provide useful information although I have found the NSNetService to have strange behaviour sometimes also. Stopping the NSNetService and re-publishing is an ugly option which seemed to work for me to some extent.
Make sure you implement ...didNotPublish... as above. Some routers filter out multicast packets, and unfortunately if you don't control the network there's not an awful lot you can do about it.
Another followup: modifying the device name seems to resolve the issue. One user noted that his iPad was discovered but not his iPhone. Bonjour Browser confirmed the presence of the iPad service with no iPhone service. Renaming the iPhone resolved the issue. This is truly an odd behavior.

How to create a Mac/PC server app that interacts with iPhone/iPad App?

Can someone please point me in the right direction to create a Mac/PC server app that runs in the background and connects to an iPad app over the local WiFi network?
No matter how I phrase a search on Google it just brings up various apps like Remote Mouse and whatnot and no tutorials or even a hint of where to start.
I just need to send simple commands from iPad to computer over local wifi. A point in the right direction and I can likely fill in the blanks.
Thank you.
Thomas
EDIT: I am using web languages for the iPad version that I will build as a native app using open source tools.
OK, then. It actually depends on what you really need. I made the assumption you need real-time and perhaps binary data transfer.
Your best bet is to write your server application using standard C or C++ so it compiles on both as simply as possible.
If you want to avoid all the burden of writing a protocol for service discovery or asking users to enter the ip address of your server you will use a mDNS implementation for your server and your iPhone app.
If I were you I would try bonjour: http://www.apple.com/support/bonjour/
on iPhone You could start here: http://developer.apple.com/library/mac/#documentation/Networking/Conceptual/NSNetServiceProgGuide/Articles/PublishingServices.html
Once you have your sockets you will have to implement a networking protocol between your server application and your iPhone app.
You will have to be careful about byte ordering and little subtle problems with latency, disconnections and other problems inherent to networking and WiFi.
In windows you will want to register your application as a service and in Mac OS X/UNIX you'll probably want to deamonize it.
Good luck!

PJSIP. Outgoing call cut off at 20 sec at certain Wi-Fi networks

What steps will reproduce the problem?
Startup application with PJSIP at iPhone 3G with iOS 4.
Make outgoing call. Start conversation.
Wait 20 seconds.
What is the expected output? What do you see instead?
Actual result: Outgoing call cut off at 20 sec. The call breaks on the phone on which I have called. And the call ends normally according to the log-file.
What version of the product are you using? On what operating system?
I use iPhone 3g with iOS 4, iPhone 2g with iOS 3, iPhone 3gs with iOS 4, iPhone 4 with iOS 4
I tried to use PJSIP 1.0.3, PJSIP 1.6, PJSIP 1.7
I have tried another sip clients at this Wi-Fi network:
Fring - the problem reproduce
Nimbuzz - the problem NOT reproduce
Please help me to solve this problem.
Sounds like you need a keepalive mechanism on the SIP connection. PJSIP supports this. Maybe you will have to enable it.
Use a packet sniffer to see what is actually going on.
You'll probably have more luck at SuperUser. Having said that, if one SIP client doesn't have this problem, while the other does, your first step should be to look at what's different between working and non-working clients.
When you say the call cuts off do you mean that media just stops flowing? Does something send you a BYE? (If the media stops flowing, and you terminate your end of the call, does the BYE go out and do you get a 200 OK back?)
Is it possible to use something like Wireshark on the far side of your wireless access point? In other words, can you see media traffic on the first hop past the Wifi network? When the call's cut off, what do you see?