Detection Camera Network - person-in-hangang/HanRiver GitHub Wiki

Connect with Server - Socket Settings

This is a connection operation for socket communication with the server. Through this connection, Detection Application can send photo and bounding box's information.

Step 1. Add the following permission to the manifest.

...
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
...

Step 2. Enter the IP address and PORT number of the server.

In CameraActivity.java

line 136

private String IP = IP_ADDRESS;
private int port = PORT_NUMBER;

line 464

 void connect(){
        mHandler = new Handler(Looper.getMainLooper());
        Log.w("connect","서버연결");
        // 받아오는거
        Thread checkUpdate = new Thread() {
            public void run() {
                // 서버 접속
                String newip = IP;
                try {
                    socket = new Socket(newip, port);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                try {
                    dos = new DataOutputStream(socket.getOutputStream());
                    dis = new DataInputStream(socket.getInputStream());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                String token ="@";
                byte[] size = getByte(data.length);
                byte[] total = new byte[size.length +token.getBytes(Charset.defaultCharset()).length+ data.length];

                System.arraycopy(size, 0,total,0,size.length);
                System.arraycopy(token.getBytes(),0,total,size.length,token.getBytes().length);
                System.arraycopy(data,0,total,(size.length+token.getBytes().length),data.length);
                while(true) {
                    try {
                        dos.writeUTF(":1:"+"@" +left +"@"+width+"@"+top+"@"+height+"@");
                        dos.flush();
                        dos.write(total, 0, total.length);
                        dos.flush();
                        socket.close();
                        break;
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }


        };
        checkUpdate.start();
    }