|
@@ -1,59 +0,0 @@
|
|
-package com.ruoyi.tcp;
|
|
|
|
-
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
-
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.InputStream;
|
|
|
|
-import java.io.PrintWriter;
|
|
|
|
-import java.net.Socket;
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
-import java.util.Date;
|
|
|
|
-
|
|
|
|
-public class EchoThread{
|
|
|
|
- private Socket client;
|
|
|
|
- PrintWriter out = null;
|
|
|
|
- InputStream in = null;
|
|
|
|
-
|
|
|
|
- public EchoThread(Socket client){
|
|
|
|
- this.client = client;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void run() {
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
- try {
|
|
|
|
- out = new PrintWriter(client.getOutputStream(),true);
|
|
|
|
- in = client.getInputStream();
|
|
|
|
- while(true){
|
|
|
|
- String inputLine="";
|
|
|
|
- byte[] temp = new byte[1024];
|
|
|
|
- int length = in.read(temp);
|
|
|
|
- inputLine+=new String(temp,0,length);
|
|
|
|
- JSONObject object = JSONObject.parseObject(inputLine);
|
|
|
|
- String st = object.get("ST").toString();
|
|
|
|
- Integer serial = Integer.parseInt(object.get("SERIAL").toString());
|
|
|
|
- if(".".equals(inputLine))
|
|
|
|
- {
|
|
|
|
- out.println("bye");
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- //传感器上报的数据===>inputLine
|
|
|
|
- System.out.println("===="+inputLine);
|
|
|
|
- //do sth
|
|
|
|
-
|
|
|
|
- //do sth
|
|
|
|
- JSONObject res = new JSONObject();
|
|
|
|
- res.put("ST",st);
|
|
|
|
- res.put("SERIAL",serial);
|
|
|
|
- res.put("MARK",1);
|
|
|
|
- res.put("TM ", sdf.format(new Date()));
|
|
|
|
- out.println(res);
|
|
|
|
- }
|
|
|
|
- in.close();
|
|
|
|
- out.close();
|
|
|
|
- client.close();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|