|
@@ -1,16 +1,83 @@
|
1
|
|
-public class CuisineTCPServer {
|
|
1
|
+import java.io.*;
|
|
2
|
+import java.net.ServerSocket;
|
|
3
|
+import java.net.Socket;
|
2
|
4
|
|
3
|
|
- private float fCurrentTemperature;
|
|
5
|
+public class CuisineTCPServer extends Thread{
|
4
|
6
|
|
|
7
|
+ private float fCurrentTemperature;
|
|
8
|
+ private ServerSocket fServerSocket;
|
5
|
9
|
|
6
|
10
|
public CuisineTCPServer()
|
7
|
11
|
{
|
8
|
|
- fCurrentTemperature = 0.0f;
|
|
12
|
+ try {
|
|
13
|
+ fServerSocket = new ServerSocket(6868);
|
|
14
|
+ start();
|
|
15
|
+
|
|
16
|
+ fCurrentTemperature = 0.0f;
|
|
17
|
+ }
|
|
18
|
+ catch(Exception ve)
|
|
19
|
+ {
|
|
20
|
+ ve.printStackTrace();
|
|
21
|
+ }
|
9
|
22
|
}
|
10
|
23
|
|
11
|
24
|
public float getCurrentTemperature()
|
12
|
25
|
{
|
13
|
|
- fCurrentTemperature += 1.1f ;
|
14
|
26
|
return fCurrentTemperature;
|
15
|
27
|
}
|
|
28
|
+
|
|
29
|
+ public void run()
|
|
30
|
+ {
|
|
31
|
+ while(true)
|
|
32
|
+ {
|
|
33
|
+ try{
|
|
34
|
+ Socket vConnection = fServerSocket.accept();
|
|
35
|
+ System.out.println("Accepted new connection");
|
|
36
|
+ new CuisineTalker(vConnection).start();
|
|
37
|
+ }
|
|
38
|
+ catch(Exception ve)
|
|
39
|
+ {
|
|
40
|
+ ve.printStackTrace();
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ }
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ private class CuisineTalker
|
|
47
|
+ extends Thread
|
|
48
|
+ {
|
|
49
|
+ private Socket fSocket;
|
|
50
|
+
|
|
51
|
+ public CuisineTalker(Socket iSocket)
|
|
52
|
+ {
|
|
53
|
+ fSocket = iSocket;
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ public void run()
|
|
57
|
+ {
|
|
58
|
+ while(true)
|
|
59
|
+ {
|
|
60
|
+ try
|
|
61
|
+ {
|
|
62
|
+ InputStream vInputStream = fSocket.getInputStream();
|
|
63
|
+ BufferedReader vBuffReader = new BufferedReader(new InputStreamReader(vInputStream));
|
|
64
|
+
|
|
65
|
+ try{
|
|
66
|
+ fCurrentTemperature = Float.parseFloat(vBuffReader.readLine());
|
|
67
|
+ }
|
|
68
|
+ catch(Exception ve)
|
|
69
|
+ {
|
|
70
|
+ ve.printStackTrace();
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ }
|
|
74
|
+ catch(Exception ve)
|
|
75
|
+ {
|
|
76
|
+ ve.printStackTrace();
|
|
77
|
+ }
|
|
78
|
+ }
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ }
|
|
82
|
+
|
16
|
83
|
}
|