I made a simple app works with socket to transfer data between client and server over local network,
Server java codes:
try {
    serverSocket = new ServerSocket(8888);
    System.out.println("Listening :8888");
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
while (true) {
    try {
        socket = serverSocket.accept();
        dataInputStream = new DataInputStream(socket.getInputStream());
        dataOutputStream = new DataOutputStream(
                socket.getOutputStream());
        System.out.println("ip: " + socket.getInetAddress());
        String message = dataInputStream.readUTF();
        // System.out.println("message: " + dataInputStream.readUTF());
        try {
            JSONObject jObj = new JSONObject(message);
            String flag = jObj.getString("flag");
            if (flag.equals("request")) {
                String request = jObj.getString("request");
                if (request.equals("getGroup"))
                    dataOutputStream.writeUTF(getGroup());
                else if (request.equals("getFood")) {
                    String groupID = jObj.getString("groupID");
                    dataOutputStream.writeUTF(getFood(groupID));
                }
            }
        } catch (JSONException | IOException e) {
            e.printStackTrace();
        }
        // dataOutputStream.writeUTF("Hello!");
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (socket != null) {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (dataInputStream != null) {
            try {
                dataInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (dataOutputStream != null) {
            try {
                dataOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
and android client codes:
class Load extends AsyncTask<String, String, String> {
    String response;
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }
    protected String doInBackground(String... args) {
        Socket socket = null;
        DataOutputStream dataOutputStream = null;
        DataInputStream dataInputStream = null;
        try {
            socket = new Socket("192.168.1.106", 8888);
            dataOutputStream = new DataOutputStream(socket.getOutputStream());
            dataInputStream = new DataInputStream(socket.getInputStream());
            dataOutputStream.writeUTF(utils.getGroup());
            response = dataInputStream.readUTF();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (socket != null) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (dataOutputStream != null) {
                try {
                    dataOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (dataInputStream != null) {
                try {
                    dataInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    protected void onPostExecute(String file_url) {
        showGroup(response);
    }
}
How many clients this can handle? Is there a better solution?
 
     
     
    