Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/main/java/org/java_websocket/server/WebSocketServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -812,23 +812,42 @@ public void broadcast(byte[] data) {
broadcast( data, connections );
}

/**
* Send a ByteBuffer to all connected endpoints
* @param data the data to send to the endpoints
*/
public void broadcast(ByteBuffer data) {
broadcast(data, connections);
}

/**
* Send a byte array to a specific collection of websocket connections
* @param data the data to send to the endpoints
* @param clients a collection of endpoints to whom the text has to be send
*/
public void broadcast(byte[] data, Collection<WebSocket> clients) {
if (data == null || clients == null) {
throw new IllegalArgumentException();
}
broadcast(ByteBuffer.wrap(data), clients);
}

/**
* Send a ByteBuffer to a specific collection of websocket connections
* @param data the data to send to the endpoints
* @param clients a collection of endpoints to whom the text has to be send
*/
public void broadcast(ByteBuffer data, Collection<WebSocket> clients) {
if (data == null || clients == null) {
throw new IllegalArgumentException();
}
Map<Draft, List<Framedata>> draftFrames = new HashMap<Draft, List<Framedata>>();
ByteBuffer byteBufferData = ByteBuffer.wrap( data );
synchronized( clients ) {
for( WebSocket client : clients ) {
if( client != null ) {
Draft draft = client.getDraft();
if( !draftFrames.containsKey( draft ) ) {
List<Framedata> frames = draft.createFrames( byteBufferData, false );
List<Framedata> frames = draft.createFrames( data, false );
draftFrames.put( draft, frames );
}
try {
Expand Down