Record Class SocketExchange
java.lang.Object
java.lang.Record
de.craftsblock.craftsnet.api.websocket.SocketExchange
- All Implemented Interfaces:
BaseExchange,AutoCloseable
public record SocketExchange(@NotNull ProtocolVersion protocolVersion, @NotNull WebSocketServer server, @NotNull WebSocketClient client)
extends Record
implements BaseExchange
The SocketExchange record represents an exchange object that provides a way to interact
with the WebSocket server and client within the context of a WebSocket connection.
It allows sending broadcast messages to all clients connected to the same WebSocket path.
- Since:
- 2.1.1-SNAPSHOT
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSocketExchange(@NotNull ProtocolVersion protocolVersion, @NotNull WebSocketServer server, @NotNull WebSocketClient client) Creates an instance of aSocketExchangerecord class. -
Method Summary
Modifier and TypeMethodDescriptionvoidBroadcasts the given data to all WebSocket clients connected to the same path as the current client.client()Gets theWebSocketClientobject associated with this exchange representing the websocket connection.voidclose()Performs last actions before the exchange is closed.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.@NotNull ProtocolVersionReturns the value of theprotocolVersionrecord component.server()Gets theWebSocketServerobject associated with this exchange the websocket client connected to.final StringtoString()Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface de.craftsblock.craftsnet.api.BaseExchange
scheme
-
Constructor Details
-
SocketExchange
public SocketExchange(@NotNull @NotNull ProtocolVersion protocolVersion, @NotNull @NotNull WebSocketServer server, @NotNull @NotNull WebSocketClient client) Creates an instance of aSocketExchangerecord class.- Parameters:
protocolVersion- the value for theprotocolVersionrecord componentserver- the value for theserverrecord componentclient- the value for theclientrecord component
-
-
Method Details
-
server
Gets theWebSocketServerobject associated with this exchange the websocket client connected to.- Returns:
- The
WebSocketServerobject.
-
client
Gets theWebSocketClientobject associated with this exchange representing the websocket connection.- Returns:
- The
WebSocketClientobject.
-
broadcast
Broadcasts the given data to all WebSocket clients connected to the same path as the current client. If the current client does not have a WebSocket path associated, the broadcast is not performed.- Parameters:
data- The data to be broadcasted to the WebSocket clients.
-
close
Performs last actions before the exchange is closed.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
protocolVersion
Returns the value of theprotocolVersionrecord component.- Specified by:
protocolVersionin interfaceBaseExchange- Returns:
- the value of the
protocolVersionrecord component
-