From 1560f3063ca90d41c0717f8ed6e1fb00fde64776 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期一, 12 八月 2024 15:56:56 +0800
Subject: [PATCH] #
---
app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java b/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java
index 13abdea..2d2c049 100644
--- a/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java
+++ b/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java
@@ -8,6 +8,15 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import android.util.Log;
+
+import com.example.agvcontroller.Item;
+
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
+
+import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
public class NettyServerHandler extends ChannelInboundHandlerAdapter {
@@ -19,6 +28,7 @@
public void channelActive(ChannelHandlerContext ctx) throws Exception {
String clientId = ctx.channel().remoteAddress().toString();
channelMap.put(clientId, ctx.channel());
+ EventBus.getDefault().post(new Item("1",clientId,"3"));
Log.d(TAG, "Client connected: " + clientId);
}
@@ -26,6 +36,7 @@
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
String clientId = ctx.channel().remoteAddress().toString();
channelMap.remove(clientId);
+ EventBus.getDefault().post(clientId);
Log.d(TAG, "Client disconnected: " + clientId);
}
@@ -79,6 +90,7 @@
}
public static void sendMessageToClient(String clientId, byte[] message) {
+
Channel channel = channelMap.get(clientId);
if (channel != null && channel.isActive()) {
ByteBuf buf = Unpooled.wrappedBuffer(message);
@@ -86,6 +98,8 @@
} else {
Log.d(TAG, "Client " + clientId + " is not connected");
}
+
+ Log.d(TAG, "Client " + clientId + " is not connected");
}
@Override
--
Gitblit v1.9.1