Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to receive data push by Netty socket client

Shulou Source: shulou.com Published: 2022-06-01 11:15:08 09月26日 Update

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!

Tags: Client client data push method Learning Task Writing problem static Service Global variable member more help practical ordinary successful next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information Xiaomi OPPO Reno macOS