- Notifications
You must be signed in to change notification settings - Fork 44
Getting started
Simply create an instance of SteamClient and then call connect() to start connecting to the steam servers.
SteamClientclient = newSteamClient();
client.connect();You can customize the configuration of the client (e.g. to specify a protocol or a ServerListProvider).
SteamConfigurationconfiguration = SteamConfiguration.create(builder -> {
builder.setProtocolTypes(ProtocolTypes.TCP);
builder.withServerListProvider(newFileServerListProvider(newFile("servers.bin")));
});
SteamClientclient = newSteamClient(configuration);To receive callbacks from the client when there is an incoming message you have to register callback consumers with a CallbackManager object. The following code registers callbacks for connection and disconnection events.
CallbackManagermanager = newCallbackManager(steamClient);
manager.subscribe(ConnectedCallback.class, this::onConnected);
manager.subscribe(DisconnectedCallback.class, this::onDisconnected);
...
privatevoidonConnected(LoggedOnCallbackcallback) {
// handle connected event here, e.g. log in
}
privatevoidonDisconnected(DisconnectedCallbackcallback) {
// handle disconnected event here, e.g. reconnect
}To actually start receiving the callbacks you need to call one of the run methods. Normally you would do this in a separate thread in a loop.
while (isRunning) {
manager.runWaitCallbacks(1000L);
}By default log messages created by JavaSteam are not redirected anywhere. You can use the DefaultLogListener which simply prints log messages to the standard output. Alternatively, you can implement the LogListener interface if you want to handle the log messages yourself.
LogManager.addListener(newDefaultLogListener());