Objective c AsyncSocket setDelegate不工作?

Objective c AsyncSocket setDelegate不工作?,objective-c,macos,cocoa,asyncsocket,Objective C,Macos,Cocoa,Asyncsocket,我正在为一个使用AsyncSocket类的游戏开发服务器。在建立连接并将套接字对象处理到播放机后,我尝试将读/写从服务器对象重新定位到播放机对象: 以下是服务器的连接方法 - (void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket { [self logMessage:@"Incoming Client" withColor:[NSColor greenColor]]; Pla

我正在为一个使用AsyncSocket类的游戏开发服务器。在建立连接并将套接字对象处理到播放机后,我尝试将读/写从服务器对象重新定位到播放机对象:

以下是服务器的连接方法

- (void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket {
    [self logMessage:@"Incoming Client" withColor:[NSColor greenColor]];

    Player *p=[[Player alloc] initWithConnection:newSocket];
    [_players addObject:p];
    [p release];

    [[[NSApplication sharedApplication] dockTile] setBadgeLabel:[NSString stringWithFormat:@"%lu",[_players count]]];
    [tableView reloadData];
}
在我的Player.m类中,我有以下
initWithconnection:
method(节选):

我正在实现所需的委托方法(事实上,我只是从以前的服务器对象复制并粘贴了这些方法来测试它),但在我看来,
setDelegate:
方法根本无法按预期工作。它不会被呼叫。将代理设置为服务器对象一切正常(我只需将传入消息传递给正确的播放器对象)

有人知道我做错了什么吗

谢谢
/D

我找到了:我忘了复制一个委托方法(
-(void)onSocket:(AsyncSocket*)sock didConnectToHost:(NSString*)主机端口:(uint16_t)p
,其中必须启动套接字的后续读取。
- (id)initWithConnection:(AsyncSocket *)connection {
  self = [super init];
  if (self) {
    ...
    _connection=[connection retain];
    if ([_connection canSafelySetDelegate]) {
      [_connection setDelegate:self];
    }
  }
  return self;
}