Re: continu to search info (Socket)
Re: continu to search info (Socket)
- Subject: Re: continu to search info (Socket)
- From: Douglas Davidson <email@hidden>
- Date: Tue, 8 May 2001 09:09:34 -0700
On Tuesday, May 8, 2001, at 06:24 AM, Denis Gauthier wrote:
AffichPort = [[NSSocketPort alloc] initWithTCPPort:PORT];
conn = [[NSConnection alloc] initWithReceivePort:AffichPort
sendPort:nil];
if (!conn)
{
NSLog(@"didn't connect");
exit(1);
}
[conn setDelegate:self];
NSLog(@"serving");
So, we have a window Open, and on another computer, we can telnet the
app. The problem we have, is :
HOW TO READ, and WRITE the information coming from this port ?
Remember that NSSocketPort is an NSPort subclass implemented using
sockets, useful for communication between two Cocoa apps. It is not a
general-purpose socket API--for that you would want CFSocket. So, the
above setup looks like you want to communicate between two Cocoa apps
using DO over sockets. Your next step would then be to set a root
object to be vended with this connection ([conn
setRootObject:someObject]). Then you need a client to connect to this
server--the client code would look similar to the above, except that you
would use initRemoteWithTCPPort:host: rather than initWithTCPPort:, and
you would make the port the sendPort rather than the receivePort (you
should just be able to set the receivePort to nil, and have an anonymous
port filled in for you). In the client code, instead of setting a root
object, you would ask for a proxy to the server (remoteObject = [conn
rootProxy]). Then you would be all set up to start sending DO messages
back and forth. I believe Chris Kane posted a complete example
earlier--you might want to search for that.
Douglas Davidson