I have been trying to send a command string to my domotics web server which is connected to a bus and then to my LAN. The command that has to be sent to the web server through the bus is a string like this: *1*1*52## where 52 is my room's power point address, and the second "1" of the command is an on switch status (0 stands for off). So the light of my room is get switched on. My webserver IP adress is: 192.168.1.36. My goal is writing the string to the server to execute commands as well as reading from that I wrote some Java Code but the program neighter reads nor writes from/to the web server. I am very frustrated about that.
Here is the code:
Any help will be appreciated!import java.io.*; import java.net.*; public class ClientExample extends Thread { ClientExample() { Thread t = new Thread(); t.start(); } public static void main(String[] args) throws InterruptedException { String str; String ip = null; String Command = null; int port; ip = "192.168.1.36"; port = 80; try { Socket s = new Socket(ip,port);//creating socket object System.out.println("port: " + s.getPort()); OutputStream outputstream = s.getOutputStream(); InputStream inputstream = s.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(inputstream)); PrintWriter out = new PrintWriter(outputstream, true); System.out.println("Connection status: " + s.isConnected()); System.out.println("Reading from socket...."); do{ str=in.readLine(); if (str!=null) System.out.print("str "+str); } while (str!=null); // Thread.sleep(5000); Command = "*1*0*52##"; // Thread.sleep(5000); System.out.println("writing to socket...."); out.write(Command); System.out.println(("Command: " + Command)); System.out.println("check for errors : " + out.checkError()); System.out.println(out); in.close(); out.close(); s.close(); } catch (IOException e) { System.out.println("an error occured"); } } }