Beginning iPhone socket programming

Discussion in 'iOS Programming' started by wanting2learn, Aug 19, 2010.

  1. wanting2learn macrumors newbie

    Aug 19, 2010

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

  2. ianray macrumors 6502

    Jun 22, 2010
  3. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    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