Re: Using NSSocketPort
Re: Using NSSocketPort
- Subject: Re: Using NSSocketPort
- From: "Michael P. Rogers" <email@hidden>
- Date: Mon, 22 Apr 2002 13:33:36 -0500
// server (init the RECEIVE port as it LISTENS for connections)
NSSocketPort *port = [[NSSocketPort alloc] initWithTCPPort:1234];
NSConnection *connection = [[NSConnection alloc]
initWithReceivePort:port sendPort:nil]];
[connection setRootObject:whateverYourVending];
// client (init the SEND port as it MAKES connections)
id server;
NSSocketPort *port = [[NSSocketPort alloc] initWithTCPPort:1234
host:@"somehost" ]];
NSConnection *connection = [NSConnection
connectionWithReceivePort:nil sendPort:port];
server = [connection rootProxy];
[server setProtocolForProxy:@protocol(someprotocol)];
Thanks to the above code my students can now send messages from the
client *to* the server. But to go in the opposite direction, do we
need to open up a second port, or can we just have the method defined
in the proxy return a value and capture that? Which is better?
I've answered part of my own question: with the above, just using
one port, we can send information back and forth, using arguments to
send from client to server, and return values to send from server to
client.
So... why do you even *need* two ports for an NSConnection? Is the
second port so that the server can *initiate* the connection, i.e.,
play the role of client?
TIA,
Michael
--
Dr. Michael P. Rogers
Office: 203G Shilling Hall
Phone: 217-424-6327 (W) 309-828-8655 (H) 309-825-6454 (C)
E-Mail: email@hidden
Web site:
http://math.millikin.edu/
Astronomy Site:
http://twincityamateurastronomers.org
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.