|
@@ -1,14 +1,15 @@
|
|
-package com.ruoyi.system;
|
|
|
|
|
|
+package com.ruoyi.tcp;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
-import java.io.PrintWriter;
|
|
|
|
|
|
+
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
+import java.io.PrintWriter;
|
|
import java.net.Socket;
|
|
import java.net.Socket;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
|
-public class EchoThread implements Runnable{
|
|
|
|
|
|
+public class EchoThread{
|
|
private Socket client;
|
|
private Socket client;
|
|
PrintWriter out = null;
|
|
PrintWriter out = null;
|
|
InputStream in = null;
|
|
InputStream in = null;
|
|
@@ -18,9 +19,8 @@ public class EchoThread implements Runnable{
|
|
this.client = client;
|
|
this.client = client;
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
public void run() {
|
|
public void run() {
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");
|
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
try {
|
|
try {
|
|
out = new PrintWriter(client.getOutputStream(),true);
|
|
out = new PrintWriter(client.getOutputStream(),true);
|
|
in = client.getInputStream();
|
|
in = client.getInputStream();
|
|
@@ -31,7 +31,7 @@ public class EchoThread implements Runnable{
|
|
inputLine+=new String(temp,0,length);
|
|
inputLine+=new String(temp,0,length);
|
|
JSONObject object = JSONObject.parseObject(inputLine);
|
|
JSONObject object = JSONObject.parseObject(inputLine);
|
|
String st = object.get("ST").toString();
|
|
String st = object.get("ST").toString();
|
|
- String serial = object.get("SERIAL").toString();
|
|
|
|
|
|
+ Integer serial = Integer.parseInt(object.get("SERIAL").toString());
|
|
if(".".equals(inputLine))
|
|
if(".".equals(inputLine))
|
|
{
|
|
{
|
|
out.println("bye");
|
|
out.println("bye");
|
|
@@ -45,7 +45,7 @@ public class EchoThread implements Runnable{
|
|
JSONObject res = new JSONObject();
|
|
JSONObject res = new JSONObject();
|
|
res.put("ST",st);
|
|
res.put("ST",st);
|
|
res.put("SERIAL",serial);
|
|
res.put("SERIAL",serial);
|
|
- res.put("MARK","1");
|
|
|
|
|
|
+ res.put("MARK",1);
|
|
res.put("TM ", sdf.format(new Date()));
|
|
res.put("TM ", sdf.format(new Date()));
|
|
out.println(res);
|
|
out.println(res);
|
|
}
|
|
}
|