0

5 台の iPod を使用して、Bluetooth 経由で単純なクライアント/サーバー ネットワークを作成しようとしています。1 台の iPod が「stop」や「go」などの基本的な文字列を 4 台の iPod に送信し、4 台の iPod がコマンドを受信するとさまざまな処理を実行します。現在、PeerPickerなしでGameKit を使用していますが、接続を開始することさえ信頼できず、複雑でした。接続すると、2 つのデバイス間で問題なくデータを送信できますが、それ以上は送信できません。

ネットワークなしで(リモコンのような)iPod「サーバー」からiPod「クライアント」に簡単な短いメッセージをブロードキャストできるようにしたいと思います。タンクや wiTap の例など、数多くの例を見てきましたが、ネットワークを必要とせずにこれほど簡単なものがないことに驚いています。

接続を開始する方法は次のとおりです。

- (IBAction) btnConnect:(id)sender
{   
    if (sender == connectServer) {
        self.currentSession = [[GKSession alloc] initWithSessionID:@"0000"   
                                                           displayName:nil
                                                           sessionMode:GKSessionModeServer]; 
        NSLog(@"Setup Server Connection");

    } else { //connectClient
        //  Peers discover themselves ... 
        self.currentSession = [[GKSession alloc] initWithSessionID:@"0000"   
                                                       displayName:nil
                                                       sessionMode:GKSessionModeClient]; 
        NSLog(@"Setup Client Connection");
    }

    amAcceptingConnections = YES;
    [self.currentSession peersWithConnectionState:GKPeerStateAvailable];
    self.currentSession.delegate = self;
    self.currentSession.disconnectTimeout = 30;
    [self.currentSession setDataReceiveHandler:self  withContext:nil];

    //  Advertise the session to peers
    self.currentSession.available = YES;
}

そして、デリゲートで didChangeState との接続を処理します

- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {
    thePeerID = [session displayNameForPeer:peerID];
    NSLog(@"didChangeState was called from peerID: %@.", thePeerID);    
    self.currentSession = session;

    switch (state) {
        case GKPeerStateAvailable:
            thePeerID = [session displayNameForPeer:peerID];
            NSLog(@"Peer %@ Available", thePeerID);
            [session connectToPeer:peerID withTimeout:30];  
            NSLog(@"Issued Peer Connection");
            //session.available = NO;  //TODO: Look at this
            break;

        case GKPeerStateUnavailable:
            NSLog(@"Peer %@ Unavailable", thePeerID);
            break;

        case GKPeerStateConnected:
            NSLog(@"Peer %@ Connected", thePeerID);
            break;

        case GKPeerStateDisconnected:
            NSLog(@"Peer %@ Disconnected", thePeerID);
            [self.currentSession release];
            currentSession = nil;
            break;  
    }
}

問題は、didChangeState メソッドが正常で準備が整ったときに起動し、動作が予測できないことです。Bluetooth か GameKit の問題かもしれませんが、他の iPod が接続を「承認」せずに接続したいのです。これは可能ですか?

ルーターとネットワークが必要になると思いますか?

ありがとうございました

4

1 に答える 1

0

私はさらに多くの調査を行い、複数の iPod 通信システムを確立するために小さな 5V ワイヤレス アクセス ポイントを使用することにしました。GameKit のものは、2 台の iPod が互いに通信するのには最適ですが、あまり信頼性が高くありません (範囲は別の問題です)。CocoaAsyncSocket は素晴らしいです。ここでは、TCP ブロードキャストと通信に使用している人が多いようです。

ここに私が取ったいくつかのステップがあります:

  • ポートとの接続を開くように「コントローラー」iPod を設定しました。
  • 私の「クライアント」iPod アプリでは、静的 IP を使用してホストとして「コントローラー」に接続します。
  • 次に、クライアントにコマンドを送信し、コマンドに応じてさまざまなことを行います

ローカル ネットワークで複数の iPod との通信に成功した人はいますか? あなたがこれをどのように達成したかを知りたいです。

ハッピーコーディング

于 2011-01-01T00:10:16.293 に答える