How to write an iphone application to control a device that exposes a telnet api - iphone

I have to write an iphone application that controls a device. This device exposes a telnet based interface. The application should ideally have user access control and customizability for each user.
I was thinking of writing C++ classes that would communicate with the device using sockets. This functionality can then be exposed through web-services that can be called by the iphone application.
However as i looked into it deeper, the api allows you to register for events using telnet and then you can receive notification when those events occur. That kinda put a spanner in the works for me. I for one dont know a "push" scenario can work with webservices.
First off i have never programmed for the iphone so far. So i am not really sure what can be done. So i was thinking if instead of having a webserver to go through, why not have the application independently running on the iphone, directly communicating with the device using sockets. The question though is, is that possible and second i am thinking it would raise a security aspect. First we could control security as everything was going through our central server. Is there a way to handle security (in the sense who has access to the device) without having a central server.
I am sorry that this seems like an unorganized post, but iam trying to brainstorm here.
Looking forward to hear your opinions.

Look up the NSPort and NSStream classes.

I'm looking to do this same thing. Have a program running on one computer and want to send/receive telnet commands from iOS. Built one for Android using the Commons library- which has a telnet client API, but don't know the best way to do it in Objective-C (without writing a telnet client library).
As a start, however, I found the OFC library on Google Code. Looks like something of a Commons-like feel, and there seems to be a telnet client. You might take a look at that.

Related

How can I build/install/run a server program to communicate with the iPhone?

I'd like to play with the idea of creating a server program that communicates with an iPhone app over socket connections. I've found several guides within Apple's documentation for client side programming (with CFNetwork, NSStream, etc) but I don't know where to begin on programming the server application, or even what language to use, or for that matter, how to deploy and run a server application on my current web hosting package through Go Daddy. A simple instant messenger style application example should get me started, but any advice is appreciated.
if you want to create socket connection is better to use CFNetwork , it has more flexibility for you I already used NSURLConnection but CFNetwork has better performance. this is my steps and how I developed my app :
configuration of server
selection C++ for my server side (service)
start to develop a client-side app for iphone to connect to server using NS classes
but I had some problems in sending and receiving message to and form server . so I changed it to CF classes it works better and faster now.
The easiest way to handle server-to-device communications is to use APNS (Apple Push Notification Services).
Communication in the other direction (device-to-server) can be handled simply with NSUrlConnection.
If you want to write your own socket code for this, well - good luck with that.
Do you want your client application to be able to run on more than one OS? If so, you might want to stay clear of anything Apple specific. Although, if you strictly want to run on iOS, using MusiGenesis' suggestion could save you a ton of time.
I have found that Python and Perl are both pretty great for socket programming. I know that Python has several libraries built in for handling HTTP requests etc. If you want to run your server as a daemon, I found this code very helpful:
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
Here is a general python sockets guide:
http://docs.python.org/howto/sockets.html
Good luck.

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!

How does iphone apps interact with server?

I am a new programmer who is new to iPhone development and server stuff. I have a lot of questions to ask.
You don't have to answer all the questions; any help is appreciated!
How does iPhone apps interact with server?
Is there a particular kind of server i should use to interact iphone app with server?
If there is no particular kind of server then what kind of server can be used?
What are their advantages and disadvantages?
What should the iPhone app (which is the client) do in order to interact with the server?
How does the server know which iPhone to send data to?
What should the server do in order to interact with iPhone app (client)?
Your best bet is to have your iPhone make web requests of a web server. Your iPhone app acts just like a web browser, making http requests to a web server, and parsing the response.
I'm building an app right now that hits PHP scripts I've written that do database work, etc, and return JSON objects. It's not fancy--I could have built a whole SOAP or RPC web service, but I didn't do that, it just makes GET requests with query-string arguments.
There are handy libraries you want to know about. Google "iPhone JSON" to find the JSON library written by Stig Brautaset, that's the one most people seem to be using. Also, rather than putting yourself through all the hoops that the iPhone's built-in web client framework requires, go get ASIHTTPRequest, a very powerful and MUCH simplified web client library.
As a general rule, you want to do as much processing on the server as possible. For instance, there's a place in my app I'm searching for events happening within a user-specified range of their local coordinates ("within 10 miles of me"). I wrote PHP to build a latitude/longitude bounding box, and query from the database based on that. That's WAY faster than bringing a bunch of events down and then asking Core Location to calculate their distance from where I'm standing.
You've asked quite a few questions so I'll try my best to answer them all:
First, you need to be a bit clearer, what type of server are you talking about? Email server, web server, lolcat server, it depends.
At the basic level, the iphone communicates over the internet. The internet uses Internet Protocol, and there are two standard protocols built atop of IP: Transmission Control Protocol, and User Datagram Protocol. Each has it's own uses and functions.
TCP/IP and UDP/IP make up the backbone of internet communication.
A more specific application protocol is built atop of these two internet protocols, with a specific format to a given application. For example, HTTP is the standard protocol for transferring HTML and other Web information between a web server to a web browser client, over TCP.
So, your iPhone would use whatever protocol is required to commuincate with the server. For more common server communication, the iOS SDK provides methods to construct messages (for example if you wish to make an HTTP request to a web server, you can use initWithContentsOfURL to send a GET request).
If you built a custom server, then you will need construct the required message protocol on the iphone, and send it to the server, using either TCP or UDP (whatever your custom server expects).

What is the best way to implement a Server-Client connection between an iPad and multiple iPhones?

Based on a college-project I'm trying to realize a relatively simple game (Poker) where an iPad acts as Server and multiple iPod-Touchs connect to it as Clients.
Gamekit seems to drop out, since those old ipod-touch-devices don't have bluetooth-support.
Are there already some Frameworks out there simplifying the process, or do I have to fall back on TCP-Streaming-Sockets and implement it myself?
For your task I suggest you have a look at ThoMoNetworking or AsyncSocket.
ThoMoNet is a very simple setup that is specifically developed for fast and easy prototyping and easy to set up. Is will automatically create a bi-partite graph between all instances of you application it finds in the local network. So If you keep your iPad as the server and the iPhones as clients this will come down to less than 10 lines of code to set up.
AsyncSocket is a commonly used framework with ports to PC as well but requires more code to write. On the other hand it will allow you to do more fancy things, should you need them.
Distributed objects are not yet available on iPhone OS, so excluding GameKit you may try using Bonjour networking. Otherwise, you may try using web services with some of the available libraries. If Bonjour and web services are not a choice/possibility, then you have to revert to old plain sockets.

How to control any IR based home appliance using iPhone? Will it require SSH/UPnP based application?

I want to use ssh protocol. I want to make an app to transmit signal that would ultimately converted to control IR based home appliances (like controlled by IR remote control. i.e. TV)
This stuff is new to me. I don't have any clear understanding about how it will be possible.
I got suggestion to use SSH:
->Install SSH on your server.
->Configure your Network / Router to forward the SSH port to server and
->Use the SSH client on the iPhone.
Now. Is it the only way?
Someone also suggested to develop UPnP base app!
Is there any sample code available using which I can learn How to transmit the signal from iPhone to do above.
Please give some guidence if anybody has done such thing before or if they know how to do?
So that I can understand the flow and put my efforts afterwards.
If I understand correctly, you want to go iPhone->IR transmitter->(some device that is controlled by IR)
If so, you probably want to use whatever protocol the IR transmitter device is expecting.
If it's not expecting anything, I would look to HTTP, rather than SSH. Implementing SSH on the iPhone sounds like a huge hassle, and the only benefit of it is the tight security. Unless the device you are controlling is a nuclear weapon, I would go with some simple HTTP authentication.
For example, if it was a TV you were controlling, you could just request http:///remote.php?action=turnonthetv from your server. Then you'd use a PHP script to generate the IR signal to turn on the TV. This moves a lot of the logic off of the iPhone, which may or may not work with what you're doing.