Commit 1b191c69 by 钱炳权

24-3-26: aflnet后端V1.0 没有Bug

parents
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>aflnetControl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>aflnetControl</name>
<description>aflnetControl</description>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.6.13</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.9.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.31</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>2.7.2</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>com.example.aflnetcontrol.AflnetControlApplication</mainClass>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package com.example.aflnetcontrol;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AflnetControlApplication {
public static void main(String[] args) {
SpringApplication.run(AflnetControlApplication.class, args);
}
}
/********************************************************************
* 版权所有(C)2023,中国电子科技集团公司第五十研究所。 *
* 文件名称: SpringContextUtil.java//文件名称
* 文件标识: QN2.489.437
* 内容摘要: 获取spring上下文//简要描述本文件的内容,包括主要模块、函数及其功能的说明
* 其它说明: 无
* 当前版本: V1.00.00
* 作者: 张思湛 中国电子科技集团公司电子科学研究院
* 完成日期: 2023年9月18日
* 修改记录1: // 修改历史记录,包括修改日期、修改者及修改内容
* 修改日期:
* 版本号:
* 修改人:
* 修改内容:
* 修改记录2: ……
********************************************************************/
package com.example.aflnetcontrol.conf;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class SpringContextUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
/********************************************************************
* 函数名称: SpringContextUtil//函数名称
* 功能描述: SpringContextUtil构造函数//函数功能、性能等的描述
* 输入参数: 无//输入参数说明,包括每个参数的作用、取值说明及参数间关系
* 输出参数: 无//对输出参数的说明
* 返 回 值: 无//函数返回值的说明
* 其它说明: 无//其它说明
* 修改日期 版本号 修改人 修改内容
*--------------------------------------------------------------------
* 2023/01/30 v1.00.00 xoxxox xoxxox
********************************************************************/
public SpringContextUtil() {
}
/********************************************************************
* 函数名称: setApplicationContext//函数名称
* 功能描述: 设置Application上下文//函数功能、性能等的描述
* 输入参数: 无//输入参数说明,包括每个参数的作用、取值说明及参数间关系
* 输出参数: 无//对输出参数的说明
* 返 回 值: 无//函数返回值的说明
* 其它说明: 无//其它说明
* 修改日期 版本号 修改人 修改内容
*--------------------------------------------------------------------
* 2023/01/30 v1.00.00 xoxxox xoxxox
********************************************************************/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (SpringContextUtil.applicationContext == null) {
SpringContextUtil.applicationContext = applicationContext;
}
}
/********************************************************************
* 函数名称: getBean//函数名称
* 功能描述: 跟据bean名称获取bean//函数功能、性能等的描述
* 输入参数: name是bean名称//输入参数说明,包括每个参数的作用、取值说明及参数间关系
* 输出参数: 无//对输出参数的说明
* 返 回 值: Object//函数返回值的说明
* 其它说明: 无//其它说明
* 修改日期 版本号 修改人 修改内容
*--------------------------------------------------------------------
* 2023/01/30 v1.00.00 xoxxox xoxxox
********************************************************************/
public static Object getBean(String name) {
return applicationContext.getBean(name);
}
/********************************************************************
* 函数名称: getBean//函数名称
* 功能描述: 跟据bean类型获取bean//函数功能、性能等的描述
* 输入参数: 无//输入参数说明,包括每个参数的作用、取值说明及参数间关系
* 输出参数: 无//对输出参数的说明
* 返 回 值: 无//函数返回值的说明
* 其它说明: 无//其它说明
* 修改日期 版本号 修改人 修改内容
*--------------------------------------------------------------------
* 2023/01/30 v1.00.00 xoxxox xoxxox
********************************************************************/
public static Object getBean(Class<?> requiredType) {
return applicationContext.getBean(requiredType);
}
}
package com.example.aflnetcontrol.conf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
\ No newline at end of file
package com.example.aflnetcontrol.conf;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component("seedProperties")
@ConfigurationProperties(prefix = "filepath")
public class seedProperties {
String seedPath;
public String getSeedPath() {
return seedPath;
}
public void setSeedPath(String seedPath) {
this.seedPath = seedPath;
}
}
\ No newline at end of file
package com.example.aflnetcontrol.constents;
public class cmdConstent {
public static final String GET_FILE_NAME = "ls -h ";
public static final String DELETE_FILE = "sudo rm -r ";
public static final String RUN_AFLNET = "afl-fuzz -d -i /home/qbq/aflnet/tutorials/live555/in-rtsp -o out-live8 " +
"-x /home/qbq/aflnet/tutorials/live555/rtsp.dict ";
public static final String RUN_PING = "ping www.baidu.com";
}
package com.example.aflnetcontrol.controller;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author
*/
@Component("WebSocket")
@ServerEndpoint("/websocket/testResult/{name}")
public class WebSocket {
private Session session; //与某个客户端连接对话,通过此对客户端发送消息
private static final ConcurrentHashMap<String, WebSocket> WEBSOCKET_CONCURRENTHASHMAP = new ConcurrentHashMap<>(); //存放所有连接的客户端
@OnOpen
public void onOpen(Session session, @PathParam(value = "name") String name) {
this.session = session; //默认客户端,没有重名
WEBSOCKET_CONCURRENTHASHMAP.put(name, this);
System.out.println("【webSocket连接成功】当前连接人数为:" + WEBSOCKET_CONCURRENTHASHMAP.size() + ",此人为:" + name);
}
@OnClose
public void onClose() {
for (String name : WEBSOCKET_CONCURRENTHASHMAP.keySet()) {
if (this == WEBSOCKET_CONCURRENTHASHMAP.get(name)) {
WEBSOCKET_CONCURRENTHASHMAP.remove(name);
break;
}
}
System.out.println("【webSocket退出成功】当前连接人数为:" + WEBSOCKET_CONCURRENTHASHMAP.size());
}
@OnError
public void onError(Session session, Throwable throwable) {
System.out.println("error:");
throwable.printStackTrace();
}
@OnMessage
public void onMessage(Session session, String message) {
System.out.println("【webSocket接收成功】内容为:" + message); //此处可以指定发送,或者群发,或者xxxx的
if (message.indexOf("name:") == 0) {
String name = message.substring(message.indexOf("name") + 5, message.indexOf(";"));
for (String senderStr : WEBSOCKET_CONCURRENTHASHMAP.keySet()) {//获取sender的Stirng
if (WEBSOCKET_CONCURRENTHASHMAP.get(senderStr).getSession() == session) {
appointSending(senderStr, name, message.substring(message.indexOf(";") + 1));
}
}
} else {
groupSending(message, session);
}
}
public void groupSending(String message, Session exIncludeSession) {
for (String name : WEBSOCKET_CONCURRENTHASHMAP.keySet()) {
try {
if (exIncludeSession == WEBSOCKET_CONCURRENTHASHMAP.get(name).session) {
continue;
}
WEBSOCKET_CONCURRENTHASHMAP.get(name).session.getBasicRemote().sendText(name + ":" + message);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void appointSending(String sender, String name, String message) {
try {
// WEBSOCKET_CONCURRENTHASHMAP.get(name).session.getBasicRemote().sendText(sender + ":" + message);
WEBSOCKET_CONCURRENTHASHMAP.get(name).session.getBasicRemote().sendText(message);
} catch (IOException e) {
e.printStackTrace();
}
}
public Session getSession() {
return session;
}
}
\ No newline at end of file
package com.example.aflnetcontrol.controller;
import com.example.aflnetcontrol.pojo.vo.AjaxResult;
import com.example.aflnetcontrol.service.seedFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@RestController
@RequestMapping("/seedFile")
public class seedFileController {
@Autowired
seedFileService service;
/**
* 种子文件查询接口
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
public AjaxResult list() {
List<String> files = null;
try {
files = service.getSeedFiles();
} catch (Exception e) {
return AjaxResult.error("种子文件获取失败!");
}
return AjaxResult.success(files);
}
/**
* 种子文件删除接口
*/
@RequestMapping(value = "/delete/{fileName}", method = RequestMethod.GET)
public AjaxResult delete(@PathVariable("fileName")String fileName) {
try {
service.delFile(fileName);
} catch (Exception e) {
return AjaxResult.error("种子文件删除失败!");
}
return AjaxResult.success("种子文件删除成功!");
}
/**
* seeFileUpload
*/
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public AjaxResult upload(MultipartFile file) {
try {
service.upload(file);
} catch (Exception e) {
return AjaxResult.error("种子文件upload失败!");
}
return AjaxResult.success("种子文件upload成功!");
}
}
package com.example.aflnetcontrol.controller;
import com.example.aflnetcontrol.pojo.vo.AjaxResult;
import com.example.aflnetcontrol.pojo.vo.cmdStartParams;
import com.example.aflnetcontrol.service.testService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class testControler {
@Autowired
testService service;
/**
* 测试启动
*/
@RequestMapping(value = "/testStart", method = RequestMethod.POST)
public AjaxResult list(@RequestBody cmdStartParams cmdStartParams) {
try {
new Thread(new Runnable() {
public void run() {
service.testStart(cmdStartParams);
}
}).start();
} catch (Exception e) {
return AjaxResult.error("测试启动失败!");
}
return AjaxResult.success("测试启动成功!");
}
/**
* 测试停止
*/
@RequestMapping(value = "/testStop", method = RequestMethod.GET)
public AjaxResult testStop() {
try {
service.testStop();
} catch (Exception e) {
return AjaxResult.error("测试停止失败!");
}
return AjaxResult.success("测试停止成功!");
}
}
package com.example.aflnetcontrol.pojo.vo;
import java.util.HashMap;
public class AjaxResult extends HashMap<String, Object> {
private static final long serialVersionUID = 1L;
/**
* 状态码
*/
public static final String CODE_TAG = "code";
/**
* 返回内容
*/
public static final String MSG_TAG = "data";
/**
* 数据对象
*/
public static final String DATA_TAG = "data";
/**
* 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
*/
public AjaxResult() {
}
/**
* 初始化一个新创建的 AjaxResult 对象
*
* @param code 状态码
* @param data 返回内容
*/
public AjaxResult(int code, String data) {
super.put(CODE_TAG, code);
super.put(MSG_TAG, data);
}
/**
* 初始化一个新创建的 AjaxResult 对象
*
* @param code 状态码
* @param msg 返回内容
* @param data 数据对象
*/
public AjaxResult(int code, String msg, Object data) {
super.put(CODE_TAG, code);
super.put(MSG_TAG, msg);
if (data != null) {
super.put(DATA_TAG, data);
}
}
/**
* 返回成功消息
*
* @return 成功消息
*/
public static AjaxResult success() {
return AjaxResult.success("success");
}
/**
* 返回成功数据
*
* @return 成功消息
*/
public static AjaxResult success(Object data) {
return AjaxResult.success("success", data);
}
/**
* 返回成功消息
*
* @param msg 返回内容
* @return 成功消息
*/
public static AjaxResult success(String msg) {
return AjaxResult.success(msg, null);
}
/**
* 返回成功消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 成功消息
*/
public static AjaxResult success(String msg, Object data) {
return new AjaxResult(200, msg, data);
}
/**
* 返回警告消息
*
* @param msg 返回内容
* @return 警告消息
*/
public static AjaxResult warn(String msg) {
return AjaxResult.warn(msg, null);
}
/**
* 返回警告消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 警告消息
*/
public static AjaxResult warn(String msg, Object data) {
return new AjaxResult(403, msg, data);
}
/**
* 返回错误消息
*
* @return 错误消息
*/
public static AjaxResult error() {
return AjaxResult.error("操作失败");
}
/**
* 返回错误消息
*
* @param msg 返回内容
* @return 错误消息
*/
public static AjaxResult error(String msg) {
return AjaxResult.error(msg, null);
}
/**
* 返回错误消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 错误消息
*/
public static AjaxResult error(String msg, Object data) {
return new AjaxResult(500, msg, data);
}
/**
* 返回错误消息
*
* @param code 状态码
* @param msg 返回内容
* @return 错误消息
*/
public static AjaxResult error(int code, String msg) {
return new AjaxResult(code, msg, null);
}
/**
* 方便链式调用
*
* @param key 键
* @param value 值
* @return 数据对象
*/
@Override
public AjaxResult put(String key, Object value) {
super.put(key, value);
return this;
}
}
\ No newline at end of file
package com.example.aflnetcontrol.pojo.vo;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data
@Getter
@Setter
public class cmdStartParams {
String netinfo; //netInfo
String protopcol; //protocol
int waiting; //usec
String nsname;//netnsname
Boolean kill;
Boolean awareMode;
Boolean regionMutationOperators;
Boolean falseNegativeMode;
String script;//script
int stateSelectionAlgo;
int seedSelectionAlgo;
}
package com.example.aflnetcontrol.pojo.vo;
import lombok.Data;
@Data
public class testReturnEntity {
String run_time;
String cycles_done;
String last_new_path;
String total_paths;
String last_uniq_crash;
String uniq_crashes;
String last_uniq_hang;
String uniq_hangs;
String now_processing;
String map_density;
String paths_timed_out;
String count_coverage;
String now_trying;
String favored_paths;
String stage_execs;
String new_edges_on;
String total_execs;
String total_crashes;
String exec_speed;
String total_tmouts;
String bit_flips;
String levels;
String byte_flips;
String pending;
String arithmetics;
String pend_fav;
String known_ints;
String own_finds;
String dictionary;
String imported;
String havoc;
String stability;
String trim;
}
package com.example.aflnetcontrol.service.impl;
import com.example.aflnetcontrol.conf.seedProperties;
import com.example.aflnetcontrol.constents.cmdConstent;
import com.example.aflnetcontrol.service.seedFileService;
import com.example.aflnetcontrol.tools.cmdTools;
import com.example.aflnetcontrol.tools.fileTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@Service
public class seedFileServiceImpl implements seedFileService {
cmdTools cmdTools = new cmdTools();
fileTools fileTools = new fileTools();
@Autowired
seedProperties properties;
@Override
public List<String> getSeedFiles() {
return cmdTools.runCmd(cmdConstent.GET_FILE_NAME+properties.getSeedPath());
}
//todo 没有执行结果提示,
@Override
public void delFile(String fileName) {
cmdTools.runCmd(cmdConstent.DELETE_FILE+properties.getSeedPath()+"/"+fileName);
}
@Override
public void upload(MultipartFile file) {
fileTools.load(file);
}
}
package com.example.aflnetcontrol.service.impl;
import com.example.aflnetcontrol.constents.cmdConstent;
import com.example.aflnetcontrol.pojo.vo.cmdStartParams;
import com.example.aflnetcontrol.service.testService;
import com.example.aflnetcontrol.tools.cmdTools;
import com.example.aflnetcontrol.tools.testControlTools;
import org.springframework.stereotype.Service;
@Service("testService")
public class testServiceImpl implements testService {
cmdTools cmdTools = new cmdTools();
//todo 不同服务不同端口
@Override
public void testStart(cmdStartParams cmdStartParams) {
testControlTools.setIsRunning(true);
String cmd = cmdTools.parse(cmdStartParams);
String finalCmd = cmdConstent.RUN_AFLNET+cmd+"/home/qbq/live555/testProgs/testOnDemandRTSPServer 8554";
System.out.println(finalCmd);
cmdTools.runProgramCmd(finalCmd);
}
@Override
public void testStop() {
testControlTools.setIsRunning(false);
}
}
package com.example.aflnetcontrol.service;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
public interface seedFileService {
public List<String> getSeedFiles();
void delFile(String fileName);
void upload(MultipartFile file);
}
package com.example.aflnetcontrol.service;
import com.example.aflnetcontrol.pojo.vo.cmdStartParams;
import java.util.List;
public interface testService {
void testStart(cmdStartParams cmdStartParams);
void testStop();
}
package com.example.aflnetcontrol.tools;
import com.example.aflnetcontrol.conf.SpringContextUtil;
import com.example.aflnetcontrol.conf.seedProperties;
import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
public class fileTools {
seedProperties properties = (seedProperties) SpringContextUtil.getBean("seedProperties");
public void load(MultipartFile file) {
try (InputStream inputStream = file.getInputStream();
FileOutputStream outputStream = new FileOutputStream(properties.getSeedPath() + "/" + file.getOriginalFilename());) {
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
bufferedOutputStream.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.example.aflnetcontrol.tools;
public class testControlTools {
private static Boolean isRunning;
public static Boolean getIsRunning() {
return isRunning;
}
public static void setIsRunning(Boolean isRunning) {
testControlTools.isRunning = isRunning;
}
}
logging:
pattern:
file: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"
file:
# 默认日志路径
path: ./log
level:
root: info
org.springframework.data.mongodb.core: debug
com.ice.Application: info
logback:
rollingPolicy:
max-file-size: 10MB
filepath:
seedPath: "/home/qbq/aflnet/tutorials/live555/in-rtsp"
spring:
application:
name: afelnet-backend
profiles:
active: dev #默认为开发环境
,--, ___ ,-.
.--., ,--.'| ,--.'|_ ,---, ,--/ /| ,---,
,--.' \ | | : ,---, | | :,' ,---,.,---.'| ,--. :/ | ,---, ,---.'|
| | /\/ : : ' ,-+-. / | : : ' : ,' .' || | : : : ' / ,-+-. / | | | :
,--.--. : : : ,---. | ' | ,--.'|' | ,---. .;__,' / ,---.' ,: : : ,--.--. ,---. | ' / ,---. ,--.'|' | | | |
/ \ : | |-, / \ ' | | | | ,"' | / \ | | | | | |: |,-. / \ / \ ' | : / \| | ,"' | ,--.__| |
.--. .-. || : :/| / / || | : | | / | | / / |:__,'| : : : .' | : ' | .--. .-. | / / ' | | \ / / | | / | | / ,' |
\__\/: . .| | .'. ' / |' : |__ | | | | |. ' / | ' : |__ : |.' | | / : \__\/: . .. ' / ' : |. \ . ' / | | | | |. ' / |
," .--.; |' : ' ' ; /|| | '.'|| | | |/ ' ; /| | | '.'|`---' ' : |: | ," .--.; |' ; :__ | | ' \ \' ; /| | | |/ ' ; |: |
/ / ,. || | | ' | / |; : ;| | |--' ' | / | ; : ; | | '/ : / / ,. |' | '.'|' : |--' ' | / | | |--' | | '/ '
; : .' \ : \ | : || , / | |/ | : | | , / | : |; : .' \ : :; |,' | : | |/ | : :|
| , .-./ |,' \ \ / ---`-' '---' \ \ / ---`-' / \ / | , .-./\ \ / '--' \ \ /'---' \ \ /
`--`---' `--' `----' `----' `-'----' `--`---' `----' `----' `----'
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>websocket client</title>
<script type="text/javascript">
var ws1 = null;
var ws2 = null;
function myFunction() {
ws1 = new WebSocket("ws://127.0.0.1:8080/websocket/testResult/" + "web"+100);
ws2 = new WebSocket("ws://127.0.0.1:8080/websocket/testResult/" + "backend"+100);
ws1.onmessage = function (evt) {
console.log(evt);
var received_msg =JSON.parse(evt.data) ;
const nameValue = Object.values(received_msg)
var context = '<div class="sendMsg">' +
'系统数据:<br/>'+
'时钟<h3>'+nameValue+'</h3><br/>'+
' </div>';
document.getElementById("sendDiv").innerHTML = context;
};
ws1.onclose = function () {
// 关闭 websocket
alert("连接已关闭...");
};
ws2.onmessage = function (evt) {
var received_msg = evt.data;
console.log("received")
alert("接收到数据:" + received_msg);
};
ws2.onclose = function () {
// 关闭 websocket
alert("连接已关闭...");
};
}
</script>
<body onload="javascript:myFunction()">
<div id="sendDiv">
</div>
</body>
</html>
\ No newline at end of file
package com.example.aflnetcontrol;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class AflnetControlApplicationTests {
@Test
void contextLoads() {
}
}
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