简体   繁体   English

仅在使用Netty响应之前,如何发送消息?

[英]How can I send a message only after previous has been responded using Netty?

I have to send a command to the server. 我必须向服务器发送命令。

  • When server replies OK, I can send the next command, if I have. 服务器答复“确定”时,如果可以的话,我可以发送下一条命令。
  • If server replies an error, I have to print it and try again later or stop depends on command. 如果服务器回复错误,则必须打印该错误并稍后重试,或者根据命令停止。
  • If the server does not reply, I have to send the command again after a few seconds. 如果服务器未回复,则必须在几秒钟后再次发送命令。

For example like AT commands. 例如像AT命令。

I know ChannelInboundHandler, but I can't create a complex architecture like this, I don't know how to create the right code structure. 我知道ChannelInboundHandler,但是我无法创建这样的复杂体系结构,也不知道如何创建正确的代码结构。

Please let me know if you are using netty for client or server implementation. 如果您将netty用于客户端或服务器实施,请告诉我。 I had similar use case, and was making use of channel pipeline to achieve the same. 我有类似的用例,并且利用通道管道来实现相同的目的。 Basically, I have one separate handler for SimpleChannelInboundHandler<Response> , in this handler subsequent request will be sent over channel as well. 基本上,我为SimpleChannelInboundHandler<Response>有一个单独的处理程序,在此处理程序中,后续请求也将通过通道发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM