I want to create an extremely simple iPhone program that will open a telnet session on a lan-connected device and send a sequence of keystrokes. Most of the code I\'ve seen
Do yourself a favor: go read at least first 6 chapters of this Steven's book in which you can find plenty of simple examples and many advices how to avoid common pitfalls with network programming. Without doing that you will end with a buggy, slow and incomplete client.
i cant repost my code here, because SO considers it spamming to repeat your answer.
check out this sample code and tutorial link. works like a charm and is really simple to implement, less than 3 minutes and you are up and going (IF you have a socket server ready).
I'd suggest you check out the Asyncsocket project:
It makes socket programming really easy; no messing with threads yourself and things happen asynchronously without much fuss.
I think there is a sample project with a client/server to get you started.
Go through this you will have to get basic idea of socket programming
http://ichuiphonedev.blogspot.in/2012/07/a-basic-idea-of-socket-programming-in.html