@@ -0,0 +1,2588 @@
+package com.androidweardocs.wearablemessage;%0D%0A%0D%0Aimport android.util.Log;%0D%0A%0D%0Aimport java.io.ByteArrayOutputStream;%0D%0Aimport java.io.IOException;%0D%0Aimport java.io.InputStream;%0D%0Aimport java.io.OutputStream;%0D%0Aimport java.net.HttpURLConnection;%0D%0Aimport java.net.MalformedURLException;%0D%0Aimport java.net.URL;%0D%0A%0D%0A/**%0D%0A * Communicate with server%0D%0A * The server is constructed by Raspberry Pi, Node.js%0D%0A * Send JSON from Android to Server%0D%0A */%0D%0Apublic class ConnectServer %7B%0D%0A    private String serverURL = %22%22;%0D%0A%0D%0A    public ConnectServer(String serverURL) %7B%0D%0A        this.serverURL = serverURL;%0D%0A    %7D%0D%0A%0D%0A    public ConnectServer(String serverURL, int serverPort) %7B%0D%0A        this.serverURL = %22http://%22 + serverURL + %22:%22 + Integer.toString(serverPort);%0D%0A    %7D%0D%0A%0D%0A    public String sendJSON(String jsonMSG)%7B%0D%0A        OutputStream os = null;%0D%0A        InputStream is = null;%0D%0A        ByteArrayOutputStream baos = null;%0D%0A        HttpURLConnection conn = null;%0D%0A        String response = %22%22;%0D%0A        URL url = null;%0D%0A        try %7B%0D%0A            url = new URL(serverURL);%0D%0A            conn = (HttpURLConnection)url.openConnection();%0D%0A            conn.setConnectTimeout(5*1000);%0D%0A            conn.setReadTimeout(5*1000);%0D%0A            conn.setRequestMethod(%22POST%22);%0D%0A            conn.setRequestProperty(%22Cache-control%22, %22no-cache%22);%0D%0A            conn.setRequestProperty(%22Content-Type%22, %22application/json%22);%0D%0A            conn.setRequestProperty(%22Accept%22, %22application/json%22);%0D%0A            conn.setDoOutput(true);%0D%0A            conn.setDoInput(true);%0D%0A%0D%0A            os = conn.getOutputStream();%0D%0A            os.write(jsonMSG.getBytes());%0D%0A            os.flush();%0D%0A            int responseCode = conn.getResponseCode();%0D%0A            Log.v(%22==RESPONSE CODE==%22, String.valueOf(responseCode));%0D%0A%0D%0A            if(responseCode == HttpURLConnection.HTTP_OK) %7B%0D%0A                is = conn.getInputStream();%0D%0A                baos = new ByteArrayOutputStream();%0D%0A                byte%5B%5D byteBuffer = new byte%5B1024%5D;%0D%0A                byte%5B%5D byteData = null;%0D%0A                int nLength = 0;%0D%0A                while((nLength = is.read(byteBuffer, 0, byteBuffer.length)) != -1)%7B%0D%0A                    baos.write(byteBuffer, 0, nLength);%0D%0A                %7D%0D%0A                byteData = baos.toByteArray();%0D%0A                response = new String(byteData);%0D%0A%0D%0A                Log.v(%22==DATA RESPONSE==%22, response);%0D%0A            %7D%0D%0A%0D%0A%0D%0A        %7D catch (MalformedURLException e) %7B%0D%0A            e.printStackTrace();%0D%0A        %7D catch (IOException e) %7B%0D%0A            e.printStackTrace();%0D%0A        %7D%0D%0A%0D%0A        return response;%0D%0A    %7D%0D%0A%7D%0D%0A

make server communication class