Skip to content

Configuration

Tigran Sargsyan edited this page Nov 22, 2020 · 4 revisions

Sonder is very easy to configure, below are the server and client configurations.


Server configuration

Server is an instance of class com.github.tix320.sonder.api.server.SonderServer.
It can be created by builder com.github.tix320.sonder.api.server.SonderServerBuilder.

SonderServerBuilder sonderServerBuilder = new SonderServerBuilder(new InetSocketAddress(8888));

or

SonderServerBuilder sonderServerBuilder = SonderServer.forAddress(new InetSocketAddress(8888));

Methods of builder:

  • workersCoreCount(int count) - specify threds pool's core count for processing connections and packets.
  • contentTimeoutDurationFactory(LongFunction factory) - timeout factory for incoming packets that will be dropped if the protocol has not had time to process them.
  • registerProtocol(ServerSideProtocol protocol) - register some protocol for communication. Can be called multiple times.

Example:

ServerSideProtocol protocol = ...; // your protocol or some built-in protocol.

SonderServer sonderServer = SonderServer.forAddress(new InetSocketAddress(8888))
	.contentTimeoutDurationFactory(contentLength -> Duration.ofMillis(contentLength / 100)) // default is hard :)
	.workersCoreCount(15) // defualt is Runtime.getRuntime().availableProcessors();
	.registerProtocol(protocol)
	.build();

It remains only to start the server.

sonderServer.start();

Client configuration

Client is an instance of class com.github.tix320.sonder.api.client.SonderClient.
It can be created by builder com.github.tix320.sonder.api.client.SonderClientBuilder.

SonderClientBuilder sonderClientBuilder = new SonderClientBuilder (new InetSocketAddress("localhost", 8888));

or

SonderClientBuilder sonderClientBuilder = SonderClient.forAddress(new InetSocketAddress("localhost", 8888));

Methods of builder:

  • contentTimeoutDurationFactory(LongFunction factory) - timeout factory for incoming packets that will be dropped if the protocol has not had time to process them.
  • registerProtocol(ClientSideProtocol protocol) - register some protocol for communication. Can be called multiple times.

Example:

ClientSideProtocol protocol = ...; // your protocol or some built-in protocol.

SonderClient sonderClient = SonderClient.forAddress(new InetSocketAddress("localhost", 8888))
	.contentTimeoutDurationFactory(contentLength -> Duration.ofMillis(contentLength / 100)) // default is hard :)
	.registerProtocol(protocol)
	.build();

It remains only to connect to the server.

sonderClient.connect();

Next -> Events

Clone this wiki locally