Re: Using NSSocketPort
Re: Using NSSocketPort
- Subject: Re: Using NSSocketPort
- From: Mike Laster <email@hidden>
- Date: Sun, 21 Apr 2002 21:30:59 -0400
On 4/21/02 8:13 PM, "Michael P. Rogers" <email@hidden> wrote:
>
At 20:26 -0400 20/4/02, Mike Laster wrote:
>
> Does anyone have any sample code on how to use NSSocketPort?
>
>
Here's an example from cocoadevcentral, written by H. Lally Singh:
>
>
http://www.cocoadevcentral.com/tutorials/showpage.php?show=00000038.php
>
>
>
// 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)];
>
>
It doesn't compile -- I believe that initWithTCPPort:host: needs to
>
be initRemoteWithTCPPort:host: -- but other than that it's fine.
>
>
Related to this, I have a question which I hope somebody can answer.
>
>
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?
This isn't really what I'm wanting to do. I'm trying to make a server for
an existing network protocol, so therefore I can't use NSConnection. I just
trying to use NSSocketPort in order to accept connections within the run
loop.
_______________________________________________
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.