I have two android tablets. they are using sockets to connect over wifi. I was able to get one client to connect and send messages to the server. How can I get a second client to connect to the server?
the ultimate goal is to get 2 or 3 android tablets running the client app to connect and send messages to the server Android Device at the same time.
some sample code from the app for the server android tablet
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);
Put all the I/O for each accepted socket into a separate thread.