views:

6579

answers:

6

I have read a lot of questions regarding this subject on this website however they didn't quiet answer my question. If you can't be ### about my goal or background skip to the question.

My Goal

Is to build a server that can run on Mac OS X 10.4+ and later, port it to Windows XP/Vista (no idea how to do that yet, but that's a problem for later).

Then let the iPhone be the client that is able to see the computer names that are running the server (through WiFi). The user of the iPhone can then select the computer name to connect to the server on that computer.

After that they can send simple text messages to each other. For example, the iPhone sends 'Knock Knock' and the server responds 'Who is there?'. Or a simple client: 'Ping', server responds 'Pong' will do just fine.

Background

I have worked with sockets in the past, but only in Visual Basic 6 with the WINSOCKET.dll it was very easy to create a TCP/IP server.

server.host = localhost;
server.port = 12203;
server.listen();

With the client I only needed to do the following to connect.

client.connect(localhost, 12203);

There were some callbacks available like connect, close, dataArrival, etc. which I could use to do anything I want.

Perhaps for the iPhone there are libraries written for it, but is it that hard to create this simple application yourself? After doing some research I understand that I have to look in the area of CFNetwork, CFHost, CFSocket, CFStream.

Question

Is there anyone that could guide me to a tutorial or post the code where you have two buttons on the iPhone. [ Start Server ] and [ Connect to Server] where the first will start a TCP/IP server on a certain port and the second connects to it.

After a connection has been made maybe also the code to send a simple 'Ping'-message to the server after the server receives this responds with a 'Pong'-message to the client.

That would really be helpful. But maybe I am asking for to much here.

A: 

I would expect you would want your server to already be started, and then you would only need a "Connect to Server" button, and then your "Ping". Otherwise, you need a separate process on your server box which responds to the "Start Server" message and starts the server.

Chris Kline
Oh, so that's how it works? To be able to detect a server as a client you send a message to a certain local ip range (Eg. 192.168.1.1 -> 255) and every server that reply's to that message you put in your TableView. Okay I'll get that.
Mark
Is there also a way you could help me with the second part of my question? How to get the ping between the two?
Mark
google broadcast port.
Lee Treveil
A: 

hey mark .. regarding your " iPhone TCP/IP Socket Server/Client Program" post .. please let me know if u have achieved the thing working ?

I trying to do something similar . plz help

Thanks

Rahul

Rahul Gupta
No dice yet. Did you have any luck so far?
Mark
+5  A: 

This is a fantastic reference and the best "working example" I've found in several hours scouring the web,

http://dev.im.ethz.ch/wiki/Socket_communication_on_the_iPhone

blackkettle
A: 

Hi Mark and Rahul, i am also looking for the same solutioin please let me know if you found the same.

Thanks, Manish Bahal

Manish Bahal
A: 

hi all i want to develop 2 programs like client / server applicaitons clients will connect to server but i want to make tihs with multi instance of iphone simulator in Xcode can u please help me?? sorry for my bad english

thanks carpatia

carpatia
This is not an answer, and I see that you created a question on this already, so you should delete this.
Brad Larson
A: 

have you tried http://github.com/mzarra/ZSync

AWright4911