Resolved Implementing a WiFi server

Discussion in 'iOS Programming' started by multinode, Feb 16, 2011.

  1. multinode, Feb 16, 2011
    Last edited: Feb 19, 2011

    multinode macrumors regular

    Joined:
    Feb 4, 2011
    #1
    In CocoaEcho (see the link below) its server's Main.m advertises the service @"_cocoaecho._tcp." and its client looks for that service to then make a connection. What is the form of an http service for a web server please? I'd like to substitute that service in CocoaEcho's Main.m on my MacBook so that my IPad's Safari can see it. I think that that would make my MacBook be a WiFi server.

    http://developer.apple.com/library/mac/#samplecode/CocoaEcho/Introduction/Intro.html

    Searching the web ... I found CocoaHTTPServer. It builds and runs on my MacBookPro. Question: what address should I put in my IPad Safari in order to see the CocoaHTTPServer please?
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
  4. multinode thread starter macrumors regular

    Joined:
    Feb 4, 2011
    #4
    Hi Balamw ... I downloaded MAMP, installed it in my MacBook Pro, and ran it. Then I tried to get my IPad's Safari to see it as a WIFI server. That didn't happen ... why please? Web services is not my strong suit.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Are you wanting a WiFi server or a web server?
     
  6. multinode, Feb 17, 2011
    Last edited by a moderator: Feb 17, 2011

    multinode thread starter macrumors regular

    Joined:
    Feb 4, 2011
    #6
    Thanx for responding Dejo.

    First, I'm trying to get my arms around how the IPad operates ... confusing to me because the paradigms are so different ... no desktop for remote disks to mount, etc.
    :confused:

    I think a WIFI server is a local wireless LAN. I think that I connect into that LAN over 802.11 and that LAN has an outlet to the web ... is that correct? And I think that a web server has a web URL that I can connect to directly using http service.

    I found some sample code for an HTTPServer ... built it and ran it on my MacBook Pro. The code for main is below. The console printed out: 2011-02-17 01:29:56.181 CocoaHTTPServer[8995:a0f] Starting server on port 64034. I'd like to access this web server from my IPad Safari, but I couldn't make that work. Can anyone help me pse?


    Code:
    int main (int argc, const char * argv[]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
        HTTPServer *server = [[HTTPServer alloc] init];
        [server setType:@"_http._tcp."];
        [server setName:@"Cocoa HTTP Server"];
        [server setDocumentRoot:[NSURL fileURLWithPath:@"/"]];
    
        NSError *startError = nil;
        if (![server start:&startError] ) {
            NSLog(@"Error starting server: %@", startError);
            } 
        else {
            NSLog(@"Starting server on port %d", [server port]);
            }
    
        [[NSRunLoop currentRunLoop] run];
    
        [pool release];
        return 0;
        }
     
  7. balamw, Feb 17, 2011
    Last edited: Feb 17, 2011

    balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #7
    It seems that you are doing this for your webapp.

    Don't bring the iPad into the mix until you have it all working. I'll post more later.

    Edit: Apache is the A in MAMP and is a standard HTTP server you don't need to roll your own HTTP server to develop a web app. For initial development you could even consider a hosted solution so you know it is set up correctly.

    Your WiFi network will generally be created by your router or a WAP.
    Apache provides web services typically on port 80 or via SSL this can be intranet or Internet services.

    Test it all out via Safari on your Mac and a remote computer before you try from the iPad

    B
     

Share This Page