首页>代码>SpringBoot使用AOP实现简单验证、日志记录、使用NettySocket转发数据>/CallSocketDemo/src/main/java/com/lyg/call/clienttest/ChatClient2.java
package com.ynbwjf.call.clienttest; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; import java.net.Socket; import java.util.UUID; public class ChatClient2 { private static Logger log = LoggerFactory.getLogger(ChatClient2.class); public static void main(String[] args) throws IOException { // BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String host = "127.0.0.1"; int port = 1001; //与服务端建立连接 Socket socket = new Socket(host, port); socket.setOOBInline(true); //建立连接后获取输出流 DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream()); DataInputStream inputStream = new DataInputStream(socket.getInputStream()); //座席注册 String str1 = "{\"jkid\":\"zxzc\",\"zxgh\":\"1102\" }" + "\r\n"; outputStream.write(str1.getBytes()); while (true) { //发送数据 // String sendStr = br.readLine() + "\r\n"; // outputStream.write(sendStr.getBytes()); //接收socket信息 String content = ""; byte[] buff = new byte[1024]; inputStream.read(buff); String buffer = new String(buff, "utf-8"); content += buffer; // log.info("info: {}", buff); String str = new String(buff); log.info("data:" + str); } } }

youwuzuichen LV11
2023年2月11日
jackyliu LV10
2022年10月27日
jaonsang LV25
2021年6月26日
飞翔的面包片 LV13
2021年6月18日
徐万强 LV9
2021年6月2日
wxm4252 LV12
2021年5月4日
李先森 LV19
2020年12月15日
15521120753 LV2
2020年12月15日
最代码官方 LV168
2020年12月13日

xkh123
3月13日
暂无贡献等级
流水本无情 LV9
2024年3月13日
Uting LV3
2023年2月21日
java605 LV2
2023年1月12日
shenmofeng11 LV1
2022年12月26日
微信网友_6252914817732608
2022年12月8日
暂无贡献等级
MVP_HC LV3
2022年11月30日
youwuzuichen LV11
2022年10月28日
jackyliu LV10
2022年10月27日
微信网友_5924921651433472
2022年4月20日
暂无贡献等级