Re: [Q] CoreFoundation functions or Cocoa classes to make a server socket?
Re: [Q] CoreFoundation functions or Cocoa classes to make a server socket?
- Subject: Re: [Q] CoreFoundation functions or Cocoa classes to make a server socket?
- From: Jens Alfke <email@hidden>
- Date: Wed, 28 Jan 2009 13:29:03 -0800
On Jan 28, 2009, at 1:06 PM, JongAm Park wrote:
I already use NSInput/OutputStream to communicate with a server.
However, to get notification from the server, my client should
register to the server, then server tries connect back to my client.
This can be done, but it won't work well in all environments...
• The client might be behind a firewall, in which case the server
won't be allowed to connect to it.
• The client might be running a local firewall, like the one in OS X,
which will similarly refuse connections.
• The client might be behind a NAT router, which means the IP address
the server sees is really that of the router, and won't connect to the
client (unless the client arranges with the router to open a public
port.)
• If the client's IP address is obtained from DHCP, it can change at
any time in the future, making the address cached by the server
invalid. At best, the server's connection attempt fails. At worst, it
connects to the wrong machine (which can easily cause security
problems if the server doesn't authenticate.)
Consumer Internet connections tend to suffer from all or most of
these, especially the NAT and DHCP issues.
At first I thought that connecting to the server and obtaining in/
out stream would do it, but it turned out that my client program
should listen to a port. However, it doesn't seem to me that there
are classes or functions in Cocoa and Core Foundation framework.
There aren't any nice high-level Cocoa classes for this. Apple's
"CocoaEcho" sample code does implement it, using a mixture of
Foundation and CFNetwork code. Unfortunately they didn't write this
sample in a form that can easily be subclassed and re-used.
Last year I needed to implement a TCP-based server in Cocoa, so I
started with CocoaEcho and refactored the code into abstract base
classes that you can subclass to do clients and/or servers. I added
some more functionality as well, like Bonjour and SSL. The result is a
little framework called MYNetwork, which you can get from
http://mooseyard.lighthouseapp.com/projects/23191-mynetwork
It also includes an implementation of a protocol I designed called
BLIP, which lets you easily & efficiently send messages back and forth
over a socket; very handy for building your own protocols on top of.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden