public final class ByondClient extends Object
Class to send string messages from Java app to BYOND server.
Simple usage example:
ByondMessage messageToSend = new ByondMessage(new ServerAddress("bagil.game.tgstation13.org", 2337), "?ping");
ByondResponse response = new ByondClient().sendMessage(messageToSend);
ServerAddress could be omitted like that: new ByondMessage("bagil.game.tgstation13.org", 2337, "ping")
Modifier and Type | Field and Description |
---|---|
static Charset |
BYOND_CHARSET
cp1251
Charset , used by BYOND. |
Constructor and Description |
---|
ByondClient() |
Modifier and Type | Method and Description |
---|---|
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 returning of response.
|
public void sendCommand(ByondMessage byondMessage) throws HostUnavailableException
byondMessage
- message to sendHostUnavailableException
- signals that requested server unavailable to connectpublic ByondResponse sendMessage(ByondMessage byondMessage) throws HostUnavailableException, UnexpectedResponseException
Sends message to BYOND server with wait and returning of response.
Method is blocking. Timeout time created from connection lag and sending/reading response time.
Unlike sendMessage(ByondMessage, int)
additional wait from timeout won't be added,
but method is still guarantee, that whole data will be got.
byondMessage
- message object to sendByondResponse
or null,
if expected response is ResponseType.NONE
HostUnavailableException
- signals that requested server unavailable to connectUnexpectedResponseException
- if somehow response has unexpected behaviorpublic ByondResponse sendMessage(ByondMessage byondMessage, int readTimeout) throws HostUnavailableException, UnexpectedResponseException
Sends message to BYOND server with wait and returning of response. Custom timeout wait could be insert.
Method is blocking. Timeout time created from connection lag, sending time and reading timeout.
If timeout expired before response will be fully read, response 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 sendreadTimeout
- timeout time to read responseByondResponse
or null,
if expected response is ResponseType.NONE
HostUnavailableException
- signals that requested server unavailable to connect.UnexpectedResponseException
- if somehow response has unexpected behaviorCopyright © 2018. All rights reserved.