2023年2月25日17:47:13
parent
327aef04b8
commit
46485cc46e
|
|
@ -164,6 +164,27 @@ public class HomeController implements Serializable {
|
||||||
load_sql_tools(0);
|
load_sql_tools(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void netty_client_menu_item(){
|
||||||
|
load_network_tools(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load_network_tools(int index){
|
||||||
|
AnchorPane fx = null;
|
||||||
|
try {
|
||||||
|
fx = FXMLLoader.load(ResourcesUtils.getResource("network-tools"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene scene = new Scene(fx);
|
||||||
|
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||||
|
stage.setScene(scene);
|
||||||
|
|
||||||
|
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||||
|
listView.getSelectionModel().select(index);
|
||||||
|
}
|
||||||
|
|
||||||
public void load_sql_tools(int index){
|
public void load_sql_tools(int index){
|
||||||
AnchorPane fx = null;
|
AnchorPane fx = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,343 @@
|
||||||
|
package com.zhangmeng.tools.controller;
|
||||||
|
|
||||||
|
import com.zhangmeng.tools.utils.ImagePath;
|
||||||
|
import com.zhangmeng.tools.utils.ResourcesUtils;
|
||||||
|
import javafx.beans.property.SimpleDoubleProperty;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.ListCell;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.control.SplitPane;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.paint.Paint;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 芊芊墨客
|
||||||
|
* @version : 1.0
|
||||||
|
* @date : 2023-02-25 14:34
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class NetWorkToolsController {
|
||||||
|
|
||||||
|
private SimpleDoubleProperty width = new SimpleDoubleProperty(0.0);
|
||||||
|
private SimpleDoubleProperty height = new SimpleDoubleProperty(0.0);
|
||||||
|
private AnchorPane root;
|
||||||
|
private AnchorPane md5;
|
||||||
|
private AnchorPane spring_security;
|
||||||
|
|
||||||
|
private AnchorPane netty_client;
|
||||||
|
|
||||||
|
public static final String color_cell = "#f4f4f4";
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ListView<ResourcesUtils.NetWorkTools> listView;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private SplitPane splitPane;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void md5_menu_item() {
|
||||||
|
load_encrypt_tools(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void spring_security_menu_item() {
|
||||||
|
load_encrypt_tools(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void video_menu_item() {
|
||||||
|
load_player(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void music_menu_item() {
|
||||||
|
load_player(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void vip_parser_menu_item() {
|
||||||
|
load_player(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void hex_16(){
|
||||||
|
load_small_tools(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void hex_16_menu_item(){
|
||||||
|
load_small_tools(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void unicode_menu_item(){
|
||||||
|
load_small_tools(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void jwt_menu_item(){
|
||||||
|
load_small_tools(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void color_choose_menu_item(){
|
||||||
|
load_small_tools(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void qr_code_menu_item(){
|
||||||
|
load_small_tools(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void base_62_menu_item(){
|
||||||
|
load_codec_tools(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void base_64_menu_item(){
|
||||||
|
load_codec_tools(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void base_32_menu_item(){
|
||||||
|
load_codec_tools(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void morse_coder_menu_item(){
|
||||||
|
load_codec_tools(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void sql_code_gen_menu_item(){
|
||||||
|
load_sql_tools(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void netty_client_menu_item(){
|
||||||
|
boolean flag = false;
|
||||||
|
if (netty_client != null){
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
netty_client(flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load_encrypt_tools(int index){
|
||||||
|
AnchorPane fx = null;
|
||||||
|
try {
|
||||||
|
fx = FXMLLoader.load(ResourcesUtils.getResource("home"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene scene = new Scene(fx);
|
||||||
|
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||||
|
stage.setScene(scene);
|
||||||
|
|
||||||
|
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||||
|
listView.getSelectionModel().select(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load_sql_tools(int index){
|
||||||
|
AnchorPane fx = null;
|
||||||
|
try {
|
||||||
|
fx = FXMLLoader.load(ResourcesUtils.getResource("sql-tools"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene scene = new Scene(fx);
|
||||||
|
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||||
|
stage.setScene(scene);
|
||||||
|
|
||||||
|
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||||
|
listView.getSelectionModel().select(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load_codec_tools(int index){
|
||||||
|
AnchorPane fx = null;
|
||||||
|
try {
|
||||||
|
fx = FXMLLoader.load(ResourcesUtils.getResource("codec-tools"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene scene = new Scene(fx);
|
||||||
|
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||||
|
stage.setScene(scene);
|
||||||
|
|
||||||
|
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||||
|
listView.getSelectionModel().select(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load_small_tools(int index){
|
||||||
|
AnchorPane fx = null;
|
||||||
|
try {
|
||||||
|
fx = FXMLLoader.load(ResourcesUtils.getResource("small-tools"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene scene = new Scene(fx);
|
||||||
|
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||||
|
stage.setScene(scene);
|
||||||
|
|
||||||
|
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||||
|
listView.getSelectionModel().select(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load_player(int index) {
|
||||||
|
AnchorPane fx = null;
|
||||||
|
try {
|
||||||
|
fx = FXMLLoader.load(ResourcesUtils.getResource("player"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene scene = new Scene(fx);
|
||||||
|
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||||
|
stage.setScene(scene);
|
||||||
|
|
||||||
|
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||||
|
listView.getSelectionModel().select(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
init();
|
||||||
|
listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (newValue != null) {
|
||||||
|
boolean flag = false;
|
||||||
|
|
||||||
|
if (newValue.getIndex() == 0) {
|
||||||
|
if (netty_client != null){
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
netty_client(flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image getImage(ResourcesUtils.NetWorkTools player){
|
||||||
|
return switch (player){
|
||||||
|
case Netty_Client_Websocket -> new Image(ImagePath.path(ImagePath.ImagePathType.MD5));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
ResourcesUtils.NetWorkTools[] values = ResourcesUtils.NetWorkTools.values();
|
||||||
|
ObservableList<ResourcesUtils.NetWorkTools> list = FXCollections.observableArrayList();
|
||||||
|
list.addAll(Arrays.asList(values));
|
||||||
|
listView.setItems(list);
|
||||||
|
listView.setFixedCellSize(40);
|
||||||
|
listView.setCellFactory(new Callback<>() {
|
||||||
|
private int position;
|
||||||
|
@Override
|
||||||
|
public ListCell<ResourcesUtils.NetWorkTools> call(ListView<ResourcesUtils.NetWorkTools> playerListView) {
|
||||||
|
Label label = new Label();
|
||||||
|
label.setPrefWidth(200);
|
||||||
|
ListCell<ResourcesUtils.NetWorkTools> listCell = new ListCell<>() {
|
||||||
|
@Override
|
||||||
|
protected void updateItem(ResourcesUtils.NetWorkTools player, boolean b) {
|
||||||
|
super.updateItem(player, b);
|
||||||
|
if (!b) {
|
||||||
|
HBox hBox = new HBox(25);
|
||||||
|
hBox.setAlignment(Pos.CENTER);
|
||||||
|
label.setText(player.getTitle());
|
||||||
|
label.setTextFill(Paint.valueOf("#000000"));
|
||||||
|
Image im = getImage(player);
|
||||||
|
ImageView iv = new ImageView(im);
|
||||||
|
iv.setPreserveRatio(true);
|
||||||
|
iv.setFitWidth(15);
|
||||||
|
hBox.getChildren().add(iv);
|
||||||
|
|
||||||
|
hBox.getChildren().add(label);
|
||||||
|
this.setGraphic(hBox);
|
||||||
|
}
|
||||||
|
this.setStyle("-fx-background-color: " + color_cell);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
listCell.hoverProperty().addListener((observableValue, aBoolean, t1) -> {
|
||||||
|
if (t1 && !label.getText().equals("")) {
|
||||||
|
position = playerListView.getItems().indexOf(label.getText());
|
||||||
|
label.setFont(new Font(16));
|
||||||
|
playerListView.getFocusModel().focus(position);
|
||||||
|
listCell.setStyle("-fx-background-color: #369e7d");
|
||||||
|
} else {
|
||||||
|
label.setPrefHeight(20);
|
||||||
|
label.setFont(new Font(13));
|
||||||
|
listCell.setStyle("-fx-background-color: " + color_cell);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return listCell;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
netty_client(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void netty_client(boolean flag) {
|
||||||
|
//默认选择第一个
|
||||||
|
listView.getSelectionModel().select(0);
|
||||||
|
|
||||||
|
if (!flag){
|
||||||
|
try {
|
||||||
|
root = FXMLLoader.load(ResourcesUtils.getResource("netty-client"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
netty_client = root;
|
||||||
|
}else {
|
||||||
|
root = netty_client;
|
||||||
|
}
|
||||||
|
common_method();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void common_method() {
|
||||||
|
splitPane.getItems().remove(1);
|
||||||
|
splitPane.getItems().add(1, root);
|
||||||
|
root.widthProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (newValue != null) {
|
||||||
|
double width = splitPane.getWidth();
|
||||||
|
NetWorkToolsController.this.width.set(width);
|
||||||
|
log.info("home:--->width:{}", width);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
root.heightProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (newValue != null) {
|
||||||
|
double height = splitPane.getHeight();
|
||||||
|
NetWorkToolsController.this.height.set(height);
|
||||||
|
log.info("home:--->height:{}", height);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.width.addListener((observable, oldValue, newValue) -> {
|
||||||
|
NetWorkToolsController.this.root.setPrefWidth(newValue.doubleValue() - listView.getWidth());
|
||||||
|
});
|
||||||
|
|
||||||
|
this.height.addListener((observable, oldValue, newValue) -> {
|
||||||
|
NetWorkToolsController.this.root.setPrefHeight(newValue.doubleValue() - listView.getHeight());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,227 @@
|
||||||
|
package com.zhangmeng.tools.controller;
|
||||||
|
|
||||||
|
import com.zhangmeng.tools.utils.AlertUtils;
|
||||||
|
import io.netty.bootstrap.Bootstrap;
|
||||||
|
import io.netty.channel.*;
|
||||||
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
|
import io.netty.channel.socket.SocketChannel;
|
||||||
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
|
import io.netty.handler.codec.string.StringEncoder;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.control.cell.TextFieldListCell;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
import javafx.util.StringConverter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 芊芊墨客
|
||||||
|
* @version : 1.0
|
||||||
|
* @date : 2023-02-25 15:04
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class NettyClientController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button send;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField key;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField value;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField url_address;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField port;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ListView<Data> param_list;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextArea result_show;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button add;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button connect;
|
||||||
|
|
||||||
|
private final SimpleObjectProperty<ChannelHandlerContext> client = new SimpleObjectProperty<>();
|
||||||
|
|
||||||
|
private ObservableList<Data> list = FXCollections.observableArrayList();
|
||||||
|
|
||||||
|
private static final int socket_port = 3333;
|
||||||
|
private static final String socket_address = "127.0.0.1";
|
||||||
|
|
||||||
|
static class Data{
|
||||||
|
private String key;
|
||||||
|
private Object value;
|
||||||
|
|
||||||
|
public Data(String key, Object value) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(Object value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type{
|
||||||
|
Ws,
|
||||||
|
Wss;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
|
||||||
|
|
||||||
|
param_list.setPlaceholder(new Label("没有数据"));
|
||||||
|
param_list.setEditable(true);
|
||||||
|
param_list.setCellFactory(new Callback<>() {
|
||||||
|
@Override
|
||||||
|
public ListCell<Data> call(ListView<Data> param) {
|
||||||
|
return new ListCell<>(){
|
||||||
|
@Override
|
||||||
|
protected void updateItem(Data data, boolean b) {
|
||||||
|
super.updateItem(data, b);
|
||||||
|
if (!b){
|
||||||
|
HBox hbox = new HBox();
|
||||||
|
hbox.setAlignment(Pos.CENTER);
|
||||||
|
hbox.getChildren().add(new Label(data.getKey() + "---" + data.getValue()));
|
||||||
|
this.setGraphic(hbox);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
param_list.setItems(list);
|
||||||
|
|
||||||
|
add.setOnAction(event -> {
|
||||||
|
|
||||||
|
if (key.getText().length() == 0){
|
||||||
|
AlertUtils.alert_warning("key不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (value.getText().length() == 0){
|
||||||
|
AlertUtils.alert_warning("value不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
list.add(new Data(key.getText(),value.getText()));
|
||||||
|
|
||||||
|
key.setText(null);
|
||||||
|
value.setText(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect.setOnAction(event -> {
|
||||||
|
String url = Type.Ws + "://" + url_address.getText() + ":" + port.getText();
|
||||||
|
log.info("url:{}",url);
|
||||||
|
if (client.getValue() == null){
|
||||||
|
new Thread(() -> {
|
||||||
|
netty_client(url_address.getText(),Integer.parseInt(port.getText()));
|
||||||
|
}).start();
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (client.getValue() != null){
|
||||||
|
AlertUtils.alert_msg("连接成功!");
|
||||||
|
}else {
|
||||||
|
AlertUtils.alert_warning("连接失败!");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
AlertUtils.alert_warning("已连接至服务器!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (port.getText().length() == 0) {
|
||||||
|
port.setText(String.valueOf(socket_port));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url_address.getText().length() == 0) {
|
||||||
|
url_address.setText(socket_address);
|
||||||
|
}
|
||||||
|
|
||||||
|
send.setOnAction(event -> {
|
||||||
|
ChannelHandlerContext channel = client.getValue();
|
||||||
|
if (channel == null){
|
||||||
|
AlertUtils.alert_warning("请连接至服务器再试!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
channel.writeAndFlush(result_show.getText());
|
||||||
|
});
|
||||||
|
if (client.getValue() == null){
|
||||||
|
new Thread(()->{
|
||||||
|
netty_client(url_address.getText(),Integer.parseInt(port.getText()));
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void netty_client(String socket_address,int socket_port) {
|
||||||
|
log.info("netty client init .......");
|
||||||
|
NioEventLoopGroup group = new NioEventLoopGroup();
|
||||||
|
try {
|
||||||
|
Bootstrap bootstrap = new Bootstrap();
|
||||||
|
bootstrap.channel(NioSocketChannel.class);
|
||||||
|
bootstrap.group(group);
|
||||||
|
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
||||||
|
@Override
|
||||||
|
protected void initChannel(SocketChannel ch) throws Exception {
|
||||||
|
ch.pipeline().addLast("client handler", new ChannelInboundHandlerAdapter() {
|
||||||
|
// 接收响应消息
|
||||||
|
@Override
|
||||||
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||||
|
log.debug("msg: {}", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在连接建立后触发 active 事件
|
||||||
|
@Override
|
||||||
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
NettyClientController.this.client.setValue(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
|
log.info("exceptionCaught");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Channel channel = bootstrap.connect(socket_address, socket_port).sync().channel();
|
||||||
|
channel.closeFuture().sync();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("client error", e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
group.shutdownGracefully().sync();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -50,6 +50,14 @@ public class AlertUtils {
|
||||||
alert.show();
|
alert.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void alert_msg(String msg) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
|
alert.initModality(Modality.APPLICATION_MODAL);
|
||||||
|
alert.setContentText(msg);
|
||||||
|
alert.setHeaderText(null);
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
|
||||||
public static void alert(String title, Parent node, Stage primaryStage){
|
public static void alert(String title, Parent node, Stage primaryStage){
|
||||||
alert(title,node,600,400,primaryStage);
|
alert(title,node,600,400,primaryStage);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -199,4 +199,34 @@ public class ResourcesUtils {
|
||||||
private String title;
|
private String title;
|
||||||
private int index;
|
private int index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum NetWorkTools{
|
||||||
|
|
||||||
|
Netty_Client_Websocket("netty websocket 客户端",0),
|
||||||
|
;
|
||||||
|
|
||||||
|
NetWorkTools(String title, int index) {
|
||||||
|
this.title = title;
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndex(int index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private int index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,12 @@
|
||||||
<MenuItem mnemonicParsing="false" text="mysql代码生成" onAction="#sql_code_gen_menu_item"/>
|
<MenuItem mnemonicParsing="false" text="mysql代码生成" onAction="#sql_code_gen_menu_item"/>
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
|
<Menu mnemonicParsing="false" text="network工具">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" text="netty-websocket工具" onAction="#netty_client_menu_item"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
</menus>
|
</menus>
|
||||||
</MenuBar>
|
</MenuBar>
|
||||||
<SplitPane fx:id="splitPane" dividerPositions="0.5" layoutY="25.0" prefHeight="575.0" prefWidth="1200.0"
|
<SplitPane fx:id="splitPane" dividerPositions="0.5" layoutY="25.0" prefHeight="575.0" prefWidth="1200.0"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.ListView?>
|
||||||
|
<?import javafx.scene.control.TextArea?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
<?import javafx.scene.text.Text?>
|
||||||
|
|
||||||
|
<AnchorPane prefHeight="649.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.tools.controller.NettyClientController">
|
||||||
|
<children>
|
||||||
|
<Label layoutX="98.0" layoutY="49.0" text="链接地址:" AnchorPane.topAnchor="49.0" />
|
||||||
|
<TextField fx:id="url_address" layoutX="169.0" layoutY="45.0" prefHeight="25.0" prefWidth="431.0" />
|
||||||
|
<Label layoutX="626.0" layoutY="49.0" text="端口:" />
|
||||||
|
<TextField fx:id="port" layoutX="662.0" layoutY="45.0" />
|
||||||
|
<Label layoutX="98.0" layoutY="94.0" text="参数:" />
|
||||||
|
<TextField fx:id="key" layoutX="169.0" layoutY="90.0" />
|
||||||
|
<Text layoutX="343.0" layoutY="107.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(key)" />
|
||||||
|
<TextField fx:id="value" layoutX="410.0" layoutY="90.0" />
|
||||||
|
<Text layoutX="588.0" layoutY="107.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(value)" />
|
||||||
|
<Label layoutX="798.0" layoutY="94.0" text="参数列表:" />
|
||||||
|
<ListView fx:id="param_list" layoutX="888.0" layoutY="44.0" prefHeight="200.0" prefWidth="241.0" AnchorPane.leftAnchor="888.0" AnchorPane.rightAnchor="71.0" AnchorPane.topAnchor="45.0" />
|
||||||
|
<TextArea fx:id="result_show" layoutX="98.0" layoutY="260.0" prefHeight="200.0" prefWidth="1031.0" AnchorPane.bottomAnchor="189.0" AnchorPane.leftAnchor="98.0" AnchorPane.rightAnchor="71.0" AnchorPane.topAnchor="260.0" />
|
||||||
|
<Button fx:id="send" layoutX="568.0" layoutY="510.0" mnemonicParsing="false" text="发送" AnchorPane.bottomAnchor="114.0" />
|
||||||
|
<Button fx:id="add" layoutX="653.0" layoutY="90.0" mnemonicParsing="false" text="添加" />
|
||||||
|
<Button fx:id="connect" layoutX="422.0" layoutY="173.0" mnemonicParsing="false" text="连接" />
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.ListView?>
|
||||||
|
<?import javafx.scene.control.Menu?>
|
||||||
|
<?import javafx.scene.control.MenuBar?>
|
||||||
|
<?import javafx.scene.control.MenuItem?>
|
||||||
|
<?import javafx.scene.control.SplitPane?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
|
||||||
|
<AnchorPane prefHeight="800.0"
|
||||||
|
prefWidth="1661.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="com.zhangmeng.tools.controller.NetWorkToolsController">
|
||||||
|
<children>
|
||||||
|
<MenuBar layoutX="14.0" layoutY="27.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||||
|
AnchorPane.topAnchor="0.0">
|
||||||
|
<menus>
|
||||||
|
<Menu mnemonicParsing="false" text="加密工具">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#md5_menu_item" text="md5 加密"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#spring_security_menu_item"
|
||||||
|
text="spring security 加密"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
|
<Menu mnemonicParsing="false" text="影音工具">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" text="视频播放" onAction="#video_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="音乐播放" onAction="#music_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="vip 视频解析" onAction="#vip_parser_menu_item"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
|
<Menu mnemonicParsing="false" text="常用小工具">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" text="16进制(Hex)" onAction="#hex_16_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="Unicode和字符串转换" onAction="#unicode_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="jwt工具" onAction="#jwt_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="颜色选择工具" onAction="#color_choose_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="二维码生成" onAction="#qr_code_menu_item"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
|
|
||||||
|
<Menu mnemonicParsing="false" text="编解码工具">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" text="Base62编码解码" onAction="#base_62_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="Base64编码解码" onAction="#base_64_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="Base32编码解码" onAction="#base_32_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="摩尔斯电码" onAction="#morse_coder_menu_item"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
|
|
||||||
|
<Menu mnemonicParsing="false" text="sql工具">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" text="mysql代码生成" onAction="#sql_code_gen_menu_item"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
|
|
||||||
|
<Menu mnemonicParsing="false" text="network工具">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" text="netty-websocket工具" onAction="#netty_client_menu_item"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
|
</menus>
|
||||||
|
</MenuBar>
|
||||||
|
<SplitPane fx:id="splitPane" dividerPositions="0.5" layoutY="25.0" prefHeight="575.0" prefWidth="1200.0"
|
||||||
|
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||||
|
AnchorPane.topAnchor="25.0">
|
||||||
|
<items>
|
||||||
|
<ListView fx:id="listView" maxWidth="300.0" minWidth="200.0" prefHeight="200.0" prefWidth="200.0"/>
|
||||||
|
<AnchorPane prefHeight="200.0" prefWidth="200.0"/>
|
||||||
|
</items>
|
||||||
|
</SplitPane>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
Loading…
Reference in New Issue