public final class NetcodeClientFactory
extends java.lang.Object
ChannelEventHandler and using an anonymous TLS cipher.
Every client provides an application id to the Netcode server. This
application id is used to ensure that only compatible clients join a single
channel. The server may also choose to accept only certain application ids.
Most methods return the object itself to allow easy method chaining.NetcodeClient| Constructor and Description |
|---|
NetcodeClientFactory(java.lang.String host,
int port,
java.lang.String appId)
Creates a new factory with the given host and port information and appId.
|
| Modifier and Type | Method and Description |
|---|---|
NetcodeClientFactory |
copy() |
NetcodeClient |
createChannel(java.lang.String userId,
ChannelConfiguration configuration)
Creates a new Netcode channel.
|
NetcodeClient |
joinChannel(java.lang.String userId,
java.lang.String channelId)
Joins an existing Netcode channel.
|
ChannelInformation[] |
listPublicChannels()
get a list of all public Netcode channels with at least one free slot.
|
NetcodeClientFactory |
runAfterBind(java.util.function.Consumer<java.net.Socket> runner)
Adds a function to the post-bind queue.
|
NetcodeClientFactory |
setEventHandler(ChannelEventHandler eventHandler) |
NetcodeClientFactory |
setMessageHandler(MessageHandler messageHandler) |
NetcodeClientFactory |
setMode(SocketMode socketMode,
SecurityMode securityMode)
Specifies both the socket mode and the security mode to use for new
connections.
|
NetcodeClientFactory |
setQuestionHandler(ClientQuestionHandler questionHandler) |
NetcodeClientFactory |
setTimeout(long timeout)
Sets a new timeout value to be used for server commands and client questions.
|
public NetcodeClientFactory(java.lang.String host,
int port,
java.lang.String appId)
host - the server address. may not be null.port - the port number of the server. must be in the range 0-65535.appId - the application id to use for this client. may not be null.public NetcodeClientFactory runAfterBind(java.util.function.Consumer<java.net.Socket> runner)
Socket or SSLSocket
as soon as it is created (but for SSLSockets before the handshake). This
allows arbitrary modification of the socket configuration. This is especially
useful for SSLSockets where more control over the security configuration may
be desired.
If the socket mode is set to SocketMode.PLAIN, the passed socket will
be of type Socket, for all other modes it will be a
SSLSocket.runner - the runner to add to the post-bind queue. may not be null.public NetcodeClientFactory setMode(SocketMode socketMode, SecurityMode securityMode)
SocketMode.PLAIN, then the securityMode must
be set to SecurityMode.ANY.java.lang.IllegalArgumentException - an illegal combination has been providedjava.lang.NullPointerException - any parameter is nullpublic NetcodeClient createChannel(java.lang.String userId, ChannelConfiguration configuration) throws java.io.IOException, ConnectionException
userId - the userId for this client. may not be null.configuration - the channel configuration to use.java.io.IOException - an exception occured in the unterlying I/O
elements.ConnectionException - a netcode connection could not be established.
Usually this indicates that some client data was
rejected by the server. See the exception type
and message for more information.public NetcodeClient joinChannel(java.lang.String userId, java.lang.String channelId) throws java.io.IOException, ConnectionException
userId - the userId for this client. may not be null.channelId - the id of the channel to join. Channel IDs are generated by
the server upon channel generation.java.io.IOException - an exception occured in the unterlying I/O
elements.ConnectionException - a netcode connection could not be established.
Usually this indicates that some client data was
rejected by the server. See the exception type
and message for more information.public ChannelInformation[] listPublicChannels() throws java.io.IOException, ConnectionException
java.io.IOExceptionConnectionException - if the server does not support SIMPLE_QUERY (v1
servers) or the server has disabled public
channels (v2 servers and above)public NetcodeClientFactory setTimeout(long timeout)
timeout - the new timeout in millisecondsjava.lang.IllegalArgumentException - the timeout is negativeNetcodeClient.ask(String, java.io.Serializable)public NetcodeClientFactory setMessageHandler(MessageHandler messageHandler)
public NetcodeClientFactory setEventHandler(ChannelEventHandler eventHandler)
public NetcodeClientFactory setQuestionHandler(ClientQuestionHandler questionHandler)
public NetcodeClientFactory copy()
Copyright © 2018. All Rights Reserved.