I'me making an application to read and write sensors from C (Server) to Java(Client).
The Server must run 24/7 and must always send new sensor data to the client. I have made a test application to send and read data from the socket.
Server:
Code:int main(int argc, char *argv[]) { char* msg = "Sensor01#10#10#10#10-Sensor02#20#20#20#20-Sensor03#30#30#30#30-Sensor04#40#40#40#40-Sensor05#50#50#50#50-Sensor06#60#60#60#60-Sensor07#70#70#70#70-Sensor08#80#80#80#80"; int clientSocket; openServerSocket(2300); bindServerSocket(); listenOnSocket(); clientSocket = connectToClient(); while(1){ sendData(msg); } return 0; }
Sendata:
Code:send(commSocket, msg, strlen(msg), 0);
The MSG variable is a test the real application will read data from the sensors.
The java client:
Code:public static void main(String[] args) throws UnknownHostException, IOException { Socket socket = new Socket("localhost", 2300); String str = "initialize"; BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); while ((str = br.readLine()) != null) { System.out.println(str); } }
As you can see i have put a while loop in the server to send all the time new data. But it never come to the client. when I remove the while loop so it will send once it will come to the client.
I think that the send function will be used when the server is complete to the end off the application.
I hope you can help me.
P.S. sorry for my bad english..



LinkBack URL
About LinkBacks


