Beginning iPhone socket programming

Discussion in 'iPhone/iPad Programming' started by wanting2learn, Aug 19, 2010.

  1. macrumors newbie

    Joined:
    Aug 19, 2010
    #1
    Hi,

    I am an experienced c/c++ programmer. I have a small windows mobile project that I must convert to the iPhone.

    It uses normal sockets to send data over wi-fi.
    e.g.
    Code:
    struct sockaddr_in  addrT;
    memset(&addrT, 0, sizeof(addrT));
    addrT.sin_family = AF_INET;
    addrT.sin_port = htons((unsigned short)lPort);
    //blah blah
    phe = gethostbyname(lpszAscii);
    // successfully got host address
    addrT.sin_addr.s_addr = *(long *)phe->h_addr; 
    // connect the socket		
    int nRet = connect(m_socket, (PSOCKADDR)&addrT, sizeof(addrT));
    //blah blah
    
    I am only beginning iPhone Programming so I need some guidance here.
    Can I use normal BSD sockets for iPhone?
    If so, are there any tutorials or sample code that I can look at??

    Thanks
     
  2. macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
  3. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #3
    Yes you can use ordinary BSD sockets. However...

    If you use blocking API's, it's recommended that you run them in another thread, so as not to block your app's main UI thread, or convert them to use an non-blocking network API. And connect() will block.

    You can also bundle a BSD socket inside an NSSocket to use it with the newer Cocoa APIs.
     

Share This Page