Commit bfaa942e authored by Jakob Geissler's avatar Jakob Geissler
Browse files

complete data

parent 99ae2d95
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
package Device;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Random;
public class FF {
ServerSocket seS;
boolean s;
Random rand;
public FF() throws IOException {
// Server auf Verbindungen auf Port 2930:
seS = new ServerSocket(2930);
s = true;
//Simulation von Sensor
rand = new Random();
System.out.println("Starting Server an waiting");
}
public void start() {
try {
// Anfrage entgegennehmen
Socket clientSocket = seS.accept();
// Holen uns eine Pipe zum Client und schicken Daten
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),
true);
System.out.println("Client request ...");
while(s){
//Neue Daten holen und verschicken
int number = rand.nextInt(300);
//wenn Daten mehr als 300 Fehler und Sensor Reset
if(number>250){
}else{
out.println("Daten: "+300);
Thread.sleep(1000);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
FF meinFrigo = null;
try {
meinFrigo = new FF();
meinFrigo.start();
} catch (IOException e) {
}
}
}
package Device;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;
public class SS {
Socket socket;
boolean connected;
public SS() throws UnknownHostException, IOException {
// Verbindung zu Port 2390 auf localhost aufbauen:
Socket socket = new Socket("127.0.0.1", 2930);
boolean c = true;
}
public void start() throws IOException {
// Ankommen von Daten:
BufferedReader in = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
while(c){
String serverData = in.readLine();
System.out.println("Client Daten: " + serverData);
}
// Socket dichtmachen:
socket.close();
}
public static void main(String[] args){
try{
SS mss = new SS();
mss.start();
}
catch(Exception e){
e.printStackTrace();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment