Package com.rcll.llsf_comm
Class ProtobufUpdBroadcastConnection
- java.lang.Object
-
- com.rcll.llsf_comm.ProtobufUpdBroadcastConnection
-
- All Implemented Interfaces:
ProtobufConnection
public class ProtobufUpdBroadcastConnection extends java.lang.Object implements ProtobufConnection
The ProtobufBroadcastPeer provides the possibility to communicate with a refbox using broadcast messages. You can send broadcast messages (UDP) by calling the enqueue method. To receive messages, register a ProtobufMessageHandler, incoming messages will be passed to your handler. To send and receive stream messages (TCP), use the ProtobufClient.
-
-
Constructor Summary
Constructors Constructor Description ProtobufUpdBroadcastConnection(java.lang.String hostname, int sendport, int recvport)Instantiates a new ProtobufBroadcastPeer.ProtobufUpdBroadcastConnection(java.lang.String hostname, int sendport, int recvport, boolean encrypt, int cipher, java.lang.String encryptionKey)Instantiates a new ProtobufBroadcastPeer with a cipher and an encryption key.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends com.google.protobuf.GeneratedMessageV3>
voidadd_message(java.lang.Class<T> c)Adds and registers a new protobuf message type.voidenqueue(com.google.protobuf.GeneratedMessageV3 msg)voidenqueue(ProtobufMessage msg)Puts a ProtobufMessage into the send queue in order to be sent out to the refbox.voidregister_handler(ProtobufMessageHandler handler)Registers a new ProtobufMessageHandler responsible for handling and deserializing incoming protobuf messages.voidsetEncrypt(boolean encrypt, int cipher, java.lang.String encryptionKey)Enables encryption with the given cipher and encryption key.voidstart(java.lang.String threadName)Opens the socket to be able to send messages and starts listening on the receive port passed to the constructor.voidstop()Stops the ProtobufBroadcastPeer and closes the sockets.
-
-
-
Constructor Detail
-
ProtobufUpdBroadcastConnection
public ProtobufUpdBroadcastConnection(java.lang.String hostname, int sendport, int recvport)Instantiates a new ProtobufBroadcastPeer. This method does not connect (see start).- Parameters:
hostname- the IP address of the refboxsendport- the port to which to sendrecvport- the port to listen on for incoming messages- See Also:
start(String)
-
ProtobufUpdBroadcastConnection
public ProtobufUpdBroadcastConnection(java.lang.String hostname, int sendport, int recvport, boolean encrypt, int cipher, java.lang.String encryptionKey)Instantiates a new ProtobufBroadcastPeer with a cipher and an encryption key. The cipher must be one of the values defined in the refbox integration manual in section 2.2.1. Use this constructor if you want to send and receive encrypted messages. If you set encrypt to false or the cipher to 0, encryption is disabled. This method does not connect (see start).- Parameters:
hostname- the IP address of the refboxsendport- the port to which to sendrecvport- the port to listen on for incoming messagesencrypt- enables or disables encryptioncipher- the cipher as defined in the refbox integration manual in section 2.2.1encryptionKey- the encryption key as String- See Also:
start(String)
-
-
Method Detail
-
setEncrypt
public void setEncrypt(boolean encrypt, int cipher, java.lang.String encryptionKey)Enables encryption with the given cipher and encryption key. From now on messages will be sent and received encrypted if you set encrypt to true and the cipher to a non-zero value.- Parameters:
encrypt- enables or disables encryptioncipher- the cipher as defined in the refbox integration manual in section 2.2.1encryptionKey- the encryption key as String
-
start
public void start(java.lang.String threadName) throws java.io.IOExceptionOpens the socket to be able to send messages and starts listening on the receive port passed to the constructor.- Throws:
java.io.IOException- Signals that the connection to the refbox cannot be established.
-
stop
public void stop()
Stops the ProtobufBroadcastPeer and closes the sockets.
-
register_handler
public void register_handler(ProtobufMessageHandler handler)
Registers a new ProtobufMessageHandler responsible for handling and deserializing incoming protobuf messages. Required if you want to access received messages. Only allows one registered handler at the same time.- Parameters:
handler- the ProtobufMessageHandler- See Also:
ProtobufMessageHandler
-
add_message
public <T extends com.google.protobuf.GeneratedMessageV3> void add_message(java.lang.Class<T> c)
Adds and registers a new protobuf message type. This is required to instantiate the correct protobuf message object when a message is received from the refbox. For example, if you want the client to be able to receive and process a GameState message, call client.<GameState>add_message(GameState.class).- Type Parameters:
T- the type of the protobuf message to register, has to extend from GeneratedMessage- Parameters:
c- the class object of the same protobuf message
-
enqueue
public void enqueue(com.google.protobuf.GeneratedMessageV3 msg)
- Specified by:
enqueuein interfaceProtobufConnection
-
enqueue
public void enqueue(ProtobufMessage msg)
Puts a ProtobufMessage into the send queue in order to be sent out to the refbox.- Specified by:
enqueuein interfaceProtobufConnection- Parameters:
msg- the ProtobufMessage to send- See Also:
ProtobufMessage
-
-