iPhone socket program - iphone

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 for sockets is overwhelming and vast overkill for what I want to do:
open telnet socket to IP address
send ascii keystrokes
Any simple code examples out there I can play with?

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.

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.

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

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).

Related

Forever Frame comet technique?

Can someone please explain me how the "Forever Frame" technique works ? A code example would be awesome! I went through all the material i could find in Google but i still don`t have much of an idea how it works.
Dylan Schiemann gives a great explanation.
In short, it uses "chunked encoding", a feature of HTTP/1.1 intended for an entirely different purpose, but which allows the server to maintain a connection to the client indefinitely, sending additional data to the client at will.
As Dylan says :
This technique is very low-latency because it avoids HTTP and TCP/IP set-up and tear-down by reusing a single long-lived connection.
http://cometdaily.com/2007/11/05/the-forever-frame-technique/
The rest of his article is well worth a read.

Using perl to talk to serial port for sat comms

This is probably an easy one, but I need to use perl to both talk to a serial port, and accept responses back from it - ideally something which would flag up to the rest of my programme that a new message has come back from the port so that I can process it?
The unit I'm using is called a RockBLOCK, it's a two-way satellite communicator module, plugs into the USB port, but presents itself as a normal serial device. Details here in case anyone is interested: http://rockblock.rock7mobile.com
Does anyone have any sample code for sending data plus also flagging if a message has come back? The first bit seems fairly straighforward, but the second less so...
Searching CPAN for the obvious terms gives me Device::SerialPort and Win32::SerialPort which both seem to do exactly what you need.

Documentation of TCP possible errors / unpredictable behaviours

I've started some time ago to work with custom-made servers, and even though I have experience to deal with the actual message exchange / serialization, etc, of client/server communications, I've had never coded an actual server from scratch.
In this sense, I have found raw TCP socket connections to be much trickier and unpredictable than I'd like.
For example, I coded a simple client/server application that would establish a long lived TCP connection, and the clients would receive push notifications from the server. Very simple, it worked very well in my test environment, even with many computers.
When I actually published this, though, I've had got lots of errors that later I would found that it was the lack of keepalive signals, which would make the connection to be cut, without giving me (either client or server) any feedback / error at all. The messages simply wouldn't be delivered, and fail silently.
I knew that TCP could break the connection, but I thought I could at least receive an error or such so I could reconnect in case of loss of connection.
This made me very insecure about rolling my own servers, as the possible errors and scenarios seem too many and unexpected, and I really don't want to learn about the unexpected behaviours when the actual application is deployed. With my current experience with server-side programming, the best way to deal with errors would be to enumerate all possible errors, and make sure I cover all exceptional cases when writing a program.
So, is there anywhere I could find a good documentation on the possible pitfalls / exceptions I could find with sockets, with how to detect them? It's been some time since I last worked with that, so I don't have any more fresh examples, but I remember that e.g. when you receive an empty message it would mean that the connection broke.
I'd also love to hear suggestions, or maybe simple libs (preferrably in C) that cover them so I can base my work in it? My main platform is linux, but a cross-platform solution is much appreciated!
Thank you!

Creating RAW Sockets tutorial/explanation?

So Im trying to further my understanding of sockets, but I want to start out at the lowest level first (well in C, not assembly lol)
However most sites that I deal with use the SOCK_STREAM or SOCK_DGRAM. However I have read around on Beejs guide....but I don't know if that actually deals with RAW sockets or not.
I'll obviously need to call SOCK_RAW in my call to sockets, but theirs not really a WHOLE lot of information about it. And this is just for learning purposes, i always try to understand the root of whats going on in abstraction.
Thanks
Assuming you're using Linux, I would look at the man pages for socket and packet as a start. From here and after reading a few other man pages to figure out how to actually send packets on the wire, I'd install Wireshark and experiment with sending hand-crafted packets and using Wireshark to capture and analyze them. You can learn a lot about the different network layers this way and how you can tweak different values in various headers.

What's the best way to handle multiple outgoing connections in Perl?

I have three TCP servers I need to connect to, each with different protocols, but all in nonblocking mode. Right now my plan is essentially opening a new IO::Socket per each one and adding them to IO::Select, then looping through can_read(). The idea is based on how servers are usually written in Perl, but it seems like it could work for clients.
I'm wondering if this is the best way to do it, furthermore I'm also wondering how I can probe each connection for disconnection, and initiate a reconnection to it without disrupting the other sockets. Any code examples would be a great help, or at least some points in the right direction on how best to do this.
You may want to use AnyEvent, or POE. Just look through the documentation, it has some nice examples to help you learn your way around.