1 Reply Latest reply on Jul 13, 2015 4:49 PM by CMata_Intel

    edison(client)-java socket(server)

    edison_esl

      How can I exchange data between java socket programming and Arduino?

      Edison is the client and Java socket is the server.

       

      ===============================================java socket  server=========================================

      import java.io.BufferedReader;

      import java.io.BufferedWriter;

      import java.io.IOException;

      import java.net.Socket;

      import java.net.SocketException;

       

       

      public class SocketItem implements Runnable {

       

       

        private BufferedReader br;

        private BufferedWriter bw;

        private Socket socket;

        private Manager manager;

       

       

        private final int EXIT = 99;

        private final int CASE_CONTROL = 0;

        private final int CASE_TRACE = 3;

       

       

        public SocketItem(BufferedReader br, BufferedWriter bw, Socket socket,

        Manager manager) {

        this.br = br;

        this.bw = bw;

        this.socket = socket;

        this.manager = manager;

        }

       

       

        @Override

        public void run() {

        System.out.println("socketitem run()");

        boolean b = true;

        String input;

        while (b) {

        System.out.println("in while loop ready to read");

       

       

        try {

       

       

      /* int inputCase = Integer.parseInt(br.readLine());

       

       

        if (inputCase == EXIT)

        break;

        switch (inputCase) {

        }*/

       

       

        //bw.write(input +" from server");

        //bw.flush();

       

       

        input = br.readLine();

        if(input == null)

        break;

        System.out.println("client : " + input);

       

        bw.write(input +" from server\n");

        bw.flush();

        System.out.println("flushed");

       

        }catch (IOException e) {

        e.printStackTrace();

        b = false;

        System.out.println("read thread exception");

        }

        }

        System.out.println("thread terminated");

        }

        public void disconnect() {

        try {

        bw.close();

        br.close();

        socket.close();

        } catch (IOException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

        }

        }

       

        private void write(String msg) {

        try {

        bw.write(msg);

        bw.flush();

        } catch (IOException e) {

        e.printStackTrace();

        }

        }

      }

      =====================================================================================

      How do I make a code in Edison to exchange the data?