diff --git a/.gradle/6.3/executionHistory/executionHistory.lock b/.gradle/6.3/executionHistory/executionHistory.lock index 5626c2c..90343c7 100644 Binary files a/.gradle/6.3/executionHistory/executionHistory.lock and b/.gradle/6.3/executionHistory/executionHistory.lock differ diff --git a/.gradle/6.3/fileHashes/fileHashes.lock b/.gradle/6.3/fileHashes/fileHashes.lock index 50f70c7..c9c7ad3 100644 Binary files a/.gradle/6.3/fileHashes/fileHashes.lock and b/.gradle/6.3/fileHashes/fileHashes.lock differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 7fd3164..8b24fb3 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/main/java/com/msb/model/ClientFrame.java b/src/main/java/com/msb/model/ClientFrame.java new file mode 100644 index 0000000..4015d55 --- /dev/null +++ b/src/main/java/com/msb/model/ClientFrame.java @@ -0,0 +1,52 @@ +package com.msb.model;/** + * @Author bingor + * @Date 2022/11/10 15:55 + * @Description: com.msb.model + * @Version: 1.0 + */ + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +/** + *@ClassName ClientFrame + *@Description TODO + *@Author bingor + *@Date 2022/11/10 15:55 + *@Version 3.0 + */ +public class ClientFrame extends Frame { + + public ClientFrame() { + TextArea ta = new TextArea(); + TextField tf = new TextField(); + this.setSize(600, 400); + this.add(ta, BorderLayout.CENTER); + this.add(tf, BorderLayout.SOUTH); + this.setVisible(true); + this.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.exit(1); + } + }); + + ta.setEditable(false); + + tf.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ta.setText(ta.getText() + tf.getText() + "\r\n"); + tf.setText(""); + } + }); + } + + public static void main(String[] args) { + new ClientFrame(); + } + +} diff --git a/src/main/java/com/msb/socket/Server.java b/src/main/java/com/msb/socket/Server.java new file mode 100644 index 0000000..be7ef0e --- /dev/null +++ b/src/main/java/com/msb/socket/Server.java @@ -0,0 +1,82 @@ +package com.msb.socket;/** + * @Author bingor + * @Date 2022/11/10 16:12 + * @Description: com.msb.socket + * @Version: 1.0 + */ + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.group.ChannelGroup; +import io.netty.channel.group.DefaultChannelGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.util.concurrent.GlobalEventExecutor; + +/** + *@ClassName Server + *@Description TODO + *@Author bingor + *@Date 2022/11/10 16:12 + *@Version 3.0 + */ +public class Server { + + private int port; + + public Server(int port) { + this.port = port; + } + + public void serverStart() { + EventLoopGroup bootGroup = new NioEventLoopGroup(1); + EventLoopGroup workGroup = new NioEventLoopGroup(3); + ServerBootstrap bootstrap = new ServerBootstrap(); + bootstrap.group(bootGroup, workGroup) + .channel(NioServerSocketChannel.class) + .childHandler(new ChannelInitializer() { + @Override + protected void initChannel(SocketChannel socketChannel) throws Exception { + socketChannel.pipeline().addLast(new Handler()); + } + }); + + try { + bootstrap.bind(this.port).sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + bootGroup.shutdownGracefully(); + workGroup.shutdownGracefully(); + } + } + + public static void main(String[] args) { + new Server(8888); + } + +} + +class Handler extends ChannelInboundHandlerAdapter { + + private static ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { +// super.channelRead(ctx, msg); + channelGroup.forEach(channel -> { + + }); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { +// super.exceptionCaught(ctx, cause); + cause.printStackTrace(); + ctx.close(); + } +}