I want to make project about java communication with hardware (wiz110sr) via LAN (Rj45). And for example, my hardware have ip address 198.168.0.1 ; port: 1202, connected with my PC(via lan/Rj45). I want show the output (such as numbers and letters) from my hardware in console netbeans.
When I running my code, appear :
" Exception in thread "Thread-0" java.lang.RuntimeException: Uncompilable source code
at mypkg.startListenForTCP$1.run(startListenForTCP.ja va:48)
at java.lang.Thread.run(Thread.java:745)
BUILD SUCCESSFUL (total time: 1 second) "
Here's the code :
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; import sun.rmi.runtime.Log; /** * * @author Owner */ public class startListenForTCP { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { Thread TCPListenerThread = new Thread(new Runnable() { @Override public void run() { Boolean run = true; String serverMessage = null; InetAddress serverAddr = null; try { Socket clientSocket = new Socket("198.168.0.1", 1202); try { char[] buffer = new char[2048]; int charsRead = 0; BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); while ((charsRead = in.read(buffer)) != -1) { String message = new String(buffer).substring(0, charsRead); Log.e("In While", "msg :"+message); } } catch(UnknownHostException e) { mHandler.post(new DisplayToast(context, "UnknownHostException")); } catch(IOException e) { mHandler.post(new DisplayToast(context, "IOException")); } finally { clientSocket.close(); } } catch (IOException e) { e.printStackTrace(); } } }); TCPListenerThread.start(); } }
Please help me