|
@@ -0,0 +1,300 @@
|
|
|
|
+package com.huimv.client.controller;
|
|
|
|
+
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.net.ServerSocket;
|
|
|
|
+import java.net.Socket;
|
|
|
|
+import java.util.Date;
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+public class SimplenessClient {
|
|
|
|
+ @Value("${farm.head}")
|
|
|
|
+ private String head;
|
|
|
|
+
|
|
|
|
+ @Value("${farm.cmd}")
|
|
|
|
+ private String cmd;
|
|
|
|
+
|
|
|
|
+ @Value("${farm.name}")
|
|
|
|
+ private String name;
|
|
|
|
+
|
|
|
|
+ @Value("${farm.end}")
|
|
|
|
+ private String end;
|
|
|
|
+
|
|
|
|
+ @Value("${farm.port}")
|
|
|
|
+ private Integer port;
|
|
|
|
+
|
|
|
|
+ @Value("${farm.ip}")
|
|
|
|
+ private String ip;
|
|
|
|
+
|
|
|
|
+ @Scheduled(cron = "0/20 * * * * ? ")
|
|
|
|
+ public void client() throws IOException {
|
|
|
|
+ System.out.println("start");
|
|
|
|
+ //建立socket向服务器发送连接请求
|
|
|
|
+ Socket socket = new Socket(ip,port);
|
|
|
|
+ InputStream inputStream;
|
|
|
|
+ inputStream = socket.getInputStream();
|
|
|
|
+ OutputStream outputStream = socket.getOutputStream();
|
|
|
|
+ //客户端向socket发送数据
|
|
|
|
+ PrintWriter printWriter = new PrintWriter(outputStream);
|
|
|
|
+ printWriter.println(head+"+"+ cmd+"+" + System.currentTimeMillis()+"+" + name+"+" + end);
|
|
|
|
+ printWriter.flush();
|
|
|
|
+ //读取数据
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
+ String readLine = bufferedReader.readLine();
|
|
|
|
+ System.out.println(readLine);
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ socket.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Scheduled(cron = "0/20 * * * * ? ")
|
|
|
|
+ public void client1() throws IOException {
|
|
|
|
+ Integer status = 0;
|
|
|
|
+ ServerSocket s = null;
|
|
|
|
+ try {
|
|
|
|
+ s = new ServerSocket(9080);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ if (e instanceof java.net.BindException) {
|
|
|
|
+ //端口被占用
|
|
|
|
+ status = 1;
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if(s!=null) {
|
|
|
|
+ s.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ //e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ s = new ServerSocket(9100);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ if (e instanceof java.net.BindException) {
|
|
|
|
+ //端口被占用
|
|
|
|
+ status = 2;
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if(s!=null) {
|
|
|
|
+ s.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ //e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (status == 1){
|
|
|
|
+ System.out.println("start111111111111");
|
|
|
|
+ //建立socket向服务器发送连接请求
|
|
|
|
+ Socket socket = new Socket(ip,port);
|
|
|
|
+ InputStream inputStream;
|
|
|
|
+ inputStream = socket.getInputStream();
|
|
|
|
+ OutputStream outputStream = socket.getOutputStream();
|
|
|
|
+ //客户端向socket发送数据
|
|
|
|
+ PrintWriter printWriter = new PrintWriter(outputStream);
|
|
|
|
+ printWriter.println(head+"+" + 2 +"+"+ System.currentTimeMillis()+"+" + name+"+" + end);
|
|
|
|
+ printWriter.flush();
|
|
|
|
+ //读取数据
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
+ String readLine = bufferedReader.readLine();
|
|
|
|
+ System.out.println(readLine);
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ socket.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (status == 2){
|
|
|
|
+ System.out.println("video");
|
|
|
|
+ //建立socket向服务器发送连接请求
|
|
|
|
+ Socket socket = new Socket(ip,port);
|
|
|
|
+ InputStream inputStream;
|
|
|
|
+ inputStream = socket.getInputStream();
|
|
|
|
+ OutputStream outputStream = socket.getOutputStream();
|
|
|
|
+ //客户端向socket发送数据
|
|
|
|
+ PrintWriter printWriter = new PrintWriter(outputStream);
|
|
|
|
+ printWriter.println(head+"+" + 3 +"+"+ System.currentTimeMillis()+"+" + name+"+" + end);
|
|
|
|
+ printWriter.flush();
|
|
|
|
+ //读取数据
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
+ String readLine = bufferedReader.readLine();
|
|
|
|
+ System.out.println(readLine);
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ socket.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //监听video
|
|
|
|
+ // 8100 嘉兴市青莲养殖科技有限公司 3
|
|
|
|
+ //8101 武义本生农业开发有限公司 4
|
|
|
|
+ //8103 黑猪场 6
|
|
|
|
+ //8104 嘉兴青莲王江泾农业发展有限公司 7
|
|
|
|
+ /* @Scheduled(cron = "0/20 * * * * ? ")
|
|
|
|
+ public void client1() throws IOException {
|
|
|
|
+ Integer status = 0;
|
|
|
|
+ ServerSocket s = null;
|
|
|
|
+ try {
|
|
|
|
+ s = new ServerSocket(8100);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ if (e instanceof java.net.BindException) {
|
|
|
|
+ //端口被占用
|
|
|
|
+ status = 3;
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if(s!=null) {
|
|
|
|
+ s.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ //e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ s = new ServerSocket(8101);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ if (e instanceof java.net.BindException) {
|
|
|
|
+ //端口被占用
|
|
|
|
+ status = 4;
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if(s!=null) {
|
|
|
|
+ s.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ //e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ s = new ServerSocket(8103);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ if (e instanceof java.net.BindException) {
|
|
|
|
+ //端口被占用
|
|
|
|
+ status = 6;
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if(s!=null) {
|
|
|
|
+ s.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ //e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ s = new ServerSocket(8104);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ if (e instanceof java.net.BindException) {
|
|
|
|
+ //端口被占用
|
|
|
|
+ status = 7;
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if(s!=null) {
|
|
|
|
+ s.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ //e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (status == 3){
|
|
|
|
+ System.out.println("嘉兴市青莲养殖科技有限公司");
|
|
|
|
+ //建立socket向服务器发送连接请求
|
|
|
|
+ Socket socket = new Socket(ip,port);
|
|
|
|
+ InputStream inputStream;
|
|
|
|
+ inputStream = socket.getInputStream();
|
|
|
|
+ OutputStream outputStream = socket.getOutputStream();
|
|
|
|
+ //客户端向socket发送数据
|
|
|
|
+ PrintWriter printWriter = new PrintWriter(outputStream);
|
|
|
|
+ printWriter.println(head+"+" + 3 +"+"+ System.currentTimeMillis()+"+" + 1234+"+" + end);
|
|
|
|
+ printWriter.flush();
|
|
|
|
+ //读取数据
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
+ String readLine = bufferedReader.readLine();
|
|
|
|
+ System.out.println(readLine);
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ socket.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (status == 4){
|
|
|
|
+ System.out.println("武义本生农业开发有限公司");
|
|
|
|
+ //建立socket向服务器发送连接请求
|
|
|
|
+ Socket socket = new Socket(ip,port);
|
|
|
|
+ InputStream inputStream;
|
|
|
|
+ inputStream = socket.getInputStream();
|
|
|
|
+ OutputStream outputStream = socket.getOutputStream();
|
|
|
|
+ //客户端向socket发送数据
|
|
|
|
+ PrintWriter printWriter = new PrintWriter(outputStream);
|
|
|
|
+ printWriter.println(head+"+" + 3 +"+"+ System.currentTimeMillis()+"+" + 2345+"+" + end);
|
|
|
|
+ printWriter.flush();
|
|
|
|
+ //读取数据
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
+ String readLine = bufferedReader.readLine();
|
|
|
|
+ System.out.println(readLine);
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ socket.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (status == 6){
|
|
|
|
+ System.out.println("黑猪场");
|
|
|
|
+ //建立socket向服务器发送连接请求
|
|
|
|
+ Socket socket = new Socket(ip,port);
|
|
|
|
+ InputStream inputStream;
|
|
|
|
+ inputStream = socket.getInputStream();
|
|
|
|
+ OutputStream outputStream = socket.getOutputStream();
|
|
|
|
+ //客户端向socket发送数据
|
|
|
|
+ PrintWriter printWriter = new PrintWriter(outputStream);
|
|
|
|
+ printWriter.println(head+"+" + 3 +"+"+ System.currentTimeMillis()+"+" + 8899+"+" + end);
|
|
|
|
+ printWriter.flush();
|
|
|
|
+ //读取数据
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
+ String readLine = bufferedReader.readLine();
|
|
|
|
+ System.out.println(readLine);
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ socket.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (status == 7){
|
|
|
|
+ System.out.println("嘉兴青莲王江泾农业发展有限公司");
|
|
|
|
+ //建立socket向服务器发送连接请求
|
|
|
|
+ Socket socket = new Socket(ip,port);
|
|
|
|
+ InputStream inputStream;
|
|
|
|
+ inputStream = socket.getInputStream();
|
|
|
|
+ OutputStream outputStream = socket.getOutputStream();
|
|
|
|
+ //客户端向socket发送数据
|
|
|
|
+ PrintWriter printWriter = new PrintWriter(outputStream);
|
|
|
|
+ printWriter.println(head+"+" + 3 +"+"+ System.currentTimeMillis()+"+" + 3456+"+" + end);
|
|
|
|
+ printWriter.flush();
|
|
|
|
+ //读取数据
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
+ String readLine = bufferedReader.readLine();
|
|
|
|
+ System.out.println(readLine);
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ socket.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|