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 が接続を「承認」せずに接続したいのです。これは可能ですか?
ルーターとネットワークが必要になると思いますか?
ありがとうございました