Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wanting2learn

macrumors newbie
Original poster
Aug 19, 2010
13
0
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
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.