How to Receive data from the Server in iPhone

client-server

In this application we will see how to receive data from the server. This is the simple login application and when you login in the screen it will display the message, whatever we set in the server page. So let see how it will be worked.

Step 1: Create a View base application using template. Give the application name “SendReceiveData”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the SendReceiveDataViewController class for you. Expand Resources and notice the template generated a separate nib, SendReceiveDatayViewController.xib, for the “SendReceiveData”.

Step 4: In the SendReceiveDataViewController.h file, we have added UITextField, UILabel, and one buttonClick method. So make the following changes in the file.

 

 

 

Step 5: Double click the SendReceiveDataViewController.xib file and open it to the Interface Builder. Drag three labels, one Round Rect Button and two TextField from the library and place it to the view window(See the figure below). Connect File’s Owner icon to the view icon and select view and drag File’s Owner icon to the “Input Your Values” and select greeting . Next drag File’s Owner icon to the first text field and select nameInput,do the same thing for the next text field and select passInput. Select the login button and bring up Connection Inspector and drag TouchUpInside to the File’s Owner icon and select buttonClick: action. Now save the SendReceiveDataViewController.xib file, close it and go back to the Xcode.

Step 6: Open the SendReceiveDataViewController.m file and make the following changes in the file:

 

 

 

Step 7: Now compile and run the application in the Simulator.

You can Download SourceCode from here SendReceiveData-1

Comments 17

  1. Hello,

    what would be the code for a “cancel” button? How can I close the pending connection before it is completed? Thanks.

    Pascal

  2. Hello,

    what would be the code for a "cancel" button? How can I close the pending connection before it is completed? Thanks.

    Pascal

  3. In our application, we are not set username and password, when user input username and password and click it then invalid message display in the screen that message comes from the server.

  4. Thanks for your answer. Is possible to download chckusr.php. It should be great to understand completly. Thanks in advance.

    If you can’t by this way, may be you can send me the file by e-mail…

  5. all you have to do on the server side is read the posted vars uname and pwd and then echo something. I did a quick if statement like this…

    This is my first app, so I don’t know how to send back specific data in vars like you would in AS3 or something like that… this is just reading the string on the page. This looks like a basic idea of how to get information to and from a web server. From there you can use the web server to manipulate your inputs and retrieve data. The possibilities are endless…. I love this stuff!

  6. all you have to do on the server side is read the posted vars uname and pwd and then echo something. I did a quick if statement like this…

    <php?
    $user = $_POST[‘uname’];

    if ($user == ‘tony’)
    {
    echo "You are the coolest guy I know";
    }else{
    echo "You suck"
    }
    ?>

    This is my first app, so I don’t know how to send back specific data in vars like you would in AS3 or something like that… this is just reading the string on the page. This looks like a basic idea of how to get information to and from a web server. From there you can use the web server to manipulate your inputs and retrieve data. The possibilities are endless…. I love this stuff!

  7. please,
    give one example on socket programming in iphone,
    how can we send message from client(iphone) to server.
    give one demo app. please.

  8. if i want it for GET .. what should i do? ..

    i am using it to login on website .. but the thing is that i m getting an error msg which is invalid username and password .. :S

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">