public class ByondClient extends Object
Class to send string messages from Java program to BYOND server.
Simple usage example:
ByondMessage messageToSend = new ByondMessage(new ServerAddress("bagil.game.tgstation13.org", 2337), "?ping");
ByondClient client = new ByondClient();
ByondResponse response = client.sendMessage(messageToSend);
This, with the same result, could be rewritten in the next way:
ByondMessage messageToSend = new ByondMessage("bagil.game.tgstation13.org", 2337, "ping");
ByondResponse response = ByondClient.create().sendMessage(messageToSend);
Constructor and Description |
---|
ByondClient() |
Modifier and Type | Method and Description |
---|---|
static ByondClient |
create()
Static method to create
ByondClient instance
without calling of constructor. |
void |
sendCommand(ByondMessage byondMessage)
Sends message to BYOND server without waiting for response.
|
ByondResponse |
sendMessage(ByondMessage byondMessage)
Sends message to BYOND server with wait and returning of response.
|
ByondResponse |
sendMessage(ByondMessage byondMessage,
int readTimeout)
Sends message to BYOND server with wait and of returning response.
|
public static ByondClient create()
ByondClient
instance
without calling of constructor.ByondClient
instance.public void sendCommand(ByondMessage byondMessage) throws HostUnavailableException
byondMessage
- message object to send.HostUnavailableException
- signals that requested server unavailable to connect.public ByondResponse sendMessage(ByondMessage byondMessage) throws HostUnavailableException, UnexpectedResponseTypeException, EmptyResponseException, UnknownResponseException
Sends message to BYOND server with wait and returning of response.
Method is blocking. Waiting time created from connection lag and sending/reading response time.
Unlike sendMessage(ByondMessage, int)
additional wait from timeout won't be added,
but method still guarantee, that whole data will be got.
byondMessage
- message object to send.ByondResponse
.
If message expecting response type is ResponseType.NONE
,
then response instance will has 'null' in 'responseData' field
and ResponseType.NONE
in 'responseType' field.HostUnavailableException
- signals that requested server unavailable to connect.UnexpectedResponseTypeException
- thrown if expected response doesn't equals to actual got.EmptyResponseException
- thrown if response was empty, but user waiting for something.
Cause could be in BYOND server itself.
Typically, it doesn't handle message which was send and, as a result, not provide any response.UnknownResponseException
- signals that response was caught, but it encoded into unknown format.public ByondResponse sendMessage(ByondMessage byondMessage, int readTimeout) throws HostUnavailableException, UnexpectedResponseTypeException, EmptyResponseException, UnknownResponseException
Sends message to BYOND server with wait and of returning response. Custom timeout wait could be insert.
Method is blocking. Waiting time created from connection lag, sending time and reading timeout.
If timeout expired before response fully read data will be incomplete, but still exist.
Zero and less timeout value means, that actual read will be performed like in sendMessage(ByondMessage)
,
without any custom timeout at all.
Method is not recommended to be used, due to extra wait time from timeout, and possibility of shredding data if timeout is too low.
byondMessage
- message object to send.readTimeout
- timeout time to read response.ByondResponse
.
If message expecting response type is ResponseType.NONE
,
then response instance will has 'null' in 'responseData' field
and ResponseType.NONE
in 'responseType' field.HostUnavailableException
- signals that requested server unavailable to connect.UnexpectedResponseTypeException
- thrown if expected response doesn't equals to actual got.EmptyResponseException
- thrown if response was empty, but user waiting for something.
Cause could be in BYOND server itself.
Typically, it doesn't handle message which was send and, as a result, not provide any response.UnknownResponseException
- signals that response was caught, but it encoded into unknown format.Copyright © 2017. All rights reserved.