私は2つのAndroidタブレットを持っています。彼らはwifi経由で接続するためにソケットを使用しています。1つのクライアントを接続して、サーバーにメッセージを送信することができました。2番目のクライアントをサーバーに接続するにはどうすればよいですか?
最終的な目標は、クライアントアプリを実行している2つまたは3つのAndroidタブレットを取得して、サーバーのAndroidデバイスに同時に接続してメッセージを送信することです。
サーバーAndroidタブレット用のアプリからのいくつかのサンプルコード
serverSocket = new ServerSocket(SERVERPORT);
while (true) {
// listen for incoming clients
Socket client = serverSocket.accept();
handler.post(new Runnable() {
@Override
public void run() {
Intent intent = new Intent();
intent.setAction("com.example.test.state");
intent.putExtra("serverStatus","Connected");
sendBroadcast(intent);
}
});
try {
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
while ((line = in.readLine()) != null) {
// Log.d("ServerActivity", line);
handler.post(new Runnable() {
@Override
public void run() {
receivedCommand = line;
Intent intent = new Intent();
intent.setAction("com.example.test.diceRolled");
intent.putExtra("receivedLine", line.trim());
sendBroadcast(intent);