2

UDP データグラムをサーバーに送信する小さな MAC OS X アプリケーションがあります。

これを行うためにココア asyncudpsockets ( http://code.google.com/p/cocoaasyncsocket/ )を使用したいのですが、「sendData」メソッドを呼び出しても何も起こらないという問題があります。

[socket sendData:[NSData dataWithBytes:stream length:length] 
          toHost:host 
            port:(uint16)port 
     withTimeout:5 
             tag:1];

stream は Byte* で、データグラムが含まれます。ホストは NSString としての IP アドレスです。

誰でも私を助けることができますか?

4

1 に答える 1

1

デリゲートを正しく設定しましたか?

[socket setDelegate:self];

それで :

[socket connectToHost:(NSString *)host
               onPort:(UInt16)port
          withTimeout:(NSTimeInterval)timeout
                error:(NSError **)errPtr];

次に、デリゲート メソッドで:

- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port
{
    [sock writeData:[NSData dataWithBytes:stream length:length] withTimeout:TIMEOUT_NONE tag:TAG_HEADER];
}

それが役立つことを願っています;-)

于 2011-10-27T13:57:52.690 に答える