Service overview
The service module (Serv) is a set of communication service framework based on NIO. It provides client and server encapsulation of TCP and UDP protocols, flexible message monitoring and message content encoding/decoding, and simple configuration. Secondary development is more convenient;
At the same time, it provides service support such as disconnection reconnection and link maintenance (heartbeat) by default. You only need to understand the business to easily complete the development work.
Maven package dependencies
<dependency> <groupId>net.ymate.platform</groupId> <artifactId>ymate-platform-serv</artifactId> <version>2.0-SNAPSHOT</version> </dependency>
Note: In the project’s pom. Add the above configuration to xml. The module has introduced core package dependencies by default, so there is no need to repeat the configuration.
Basic concepts
Session
Used between client and server The object of maintaining connection status and sending messages;
Encoding/Decoding (Codec)
Currently provides the following two encoding/decoding Developers can extend it by themselves by implementing the ICodec interface;
NioStringCodec: uses byte[4] as the message header to record the string message encoding/decoding of the message body length. Converter;
TextLineCodec: A codec/decoder used to parse string messages that use carriage return and line feed characters (\r\n) as the end of the message;
Built-in service (Service)
Currently provides the following two built-in services, and more services are being continuously improved...;
IHeartbeatService: Built-in link maintenance (heartbeat) service, this service will send heartbeat messages to the server at the time interval configured by the parameters after successfully establishing a connection with the server (the heartbeat message content is by default is 0 characters, the content of the heartbeat message can be set through the custom parameter heartbeat_message);
IReconnectService: Built-in disconnection and reconnection service, when the connection status of the service is abnormal, it will try to reconnect with the server establish connection;