Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to receive data push by Netty socket client

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how the Netty socket client receives data push". In the daily operation, I believe that many people have doubts about how the Netty socket client receives data push. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how the Netty socket client receives data push". Next, please follow the editor to study!

When the server disconnects, the client needs to reconnect.

Erroneous writing:

When judging whether to establish a connection according to the global member non-static variable connectStatus. The updated value cannot be read.

The latest value can be read when connectStatus is changed to a global static variable, but it will cause the task in the thread pool to be canceled in time and the server will be connected multiple times. As a result, the data pushed by the server cannot be received.

Note about reconnection:

ChannelFuture future = client.connect (socketIp, port); future.awaitUninterruptibly ()

Initialize the connection using this

Future.awaitUninterruptibly

Await () cannot be added when asynchronous timing reconnection is performed on channelInactive, which will cause the program to block.

Problems caused by the above code:

The bizarre problem:

When the red method is not a static method, the scheduled task of the ordinary member method will not be executed.

The best way to write:

Schedule is used to delay execution, and if the listening result is not connected successfully, the recursive operation is performed; otherwise, the task is stopped.

At this point, the study on "how Netty socket clients receive data push" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report