为了账号安全,请及时绑定邮箱和手机立即绑定

Spring集成TCP服务器打印传入消息

Spring集成TCP服务器打印传入消息

江户川乱折腾 2022-07-20 20:58:44
我现在正在尝试一段时间来开始使用 Spring Integration,但不幸的是无法让它工作。我想让一个服务器监听 TCP 端口并打印出从客户端发送给它的数据。我的客户端是另一个命令行工具,但因为我无法让它工作,我正在使用这个虚拟客户端发送消息。在这里我的虚拟客户发送消息。String host = "localhost";int port = 8000;InetAddress address = InetAddress.getByName(host);socket = new Socket(address, port);//Send the message to the serverOutputStream os = socket.getOutputStream();OutputStreamWriter osw = new OutputStreamWriter(os);BufferedWriter bw = new BufferedWriter(osw);String myMessage = "THIS IS MY MESSAGE!";String sendMessage = myMessage + "\n";bw.write(sendMessage);bw.flush();System.out.println("Message sent to the server : "+ sendMessage);//Get the return message from the serverInputStream is = socket.getInputStream();InputStreamReader isr = new InputStreamReader(is);BufferedReader br = new BufferedReader(isr);String message = br.readLine();System.out.println("Message received from the server : " + message);当我使用命令行工具的实际客户端时,连接也会建立,但任何后续消息都会发送 throw SocketTimeoutException。我感谢任何帮助,以及对使用注释的 TCP 的 Spring 集成教程的任何建议!谢谢!
查看完整描述

1 回答

?
有只小跳蛙

TA贡献1824条经验 获得超8个赞

要从客户端打印数据,只需WireTapfromTcportoEcho通道上放置一个,然后将其接入其他通道进行打印即可。通常LoggingHandler,拥有该窃听频道的订阅者就足够了。

您可以在参考手册中查看更多信息:https ://docs.spring.io/spring-integration/docs/current/reference/html/#channel-interceptors


查看完整回答
反对 回复 2022-07-20
  • 1 回答
  • 0 关注
  • 125 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号