Skip to content

Commit 41cf972

Browse files
authored
Merge pull request TooTallNate#712 from PhilipRoman/master
Added a broadcast method for ByteBuffers
2 parents 7f31927 + c074a94 commit 41cf972

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/main/java/org/java_websocket/server/WebSocketServer.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,23 +812,42 @@ public void broadcast(byte[] data) {
812812
broadcast( data, connections );
813813
}
814814

815+
/**
816+
* Send a ByteBuffer to all connected endpoints
817+
* @param data the data to send to the endpoints
818+
*/
819+
public void broadcast(ByteBuffer data) {
820+
broadcast(data, connections);
821+
}
822+
815823
/**
816824
* Send a byte array to a specific collection of websocket connections
817825
* @param data the data to send to the endpoints
818826
* @param clients a collection of endpoints to whom the text has to be send
819827
*/
820828
public void broadcast(byte[] data, Collection<WebSocket> clients) {
829+
if (data == null || clients == null) {
830+
throw new IllegalArgumentException();
831+
}
832+
broadcast(ByteBuffer.wrap(data), clients);
833+
}
834+
835+
/**
836+
* Send a ByteBuffer to a specific collection of websocket connections
837+
* @param data the data to send to the endpoints
838+
* @param clients a collection of endpoints to whom the text has to be send
839+
*/
840+
public void broadcast(ByteBuffer data, Collection<WebSocket> clients) {
821841
if (data == null || clients == null) {
822842
throw new IllegalArgumentException();
823843
}
824844
Map<Draft, List<Framedata>> draftFrames = new HashMap<Draft, List<Framedata>>();
825-
ByteBuffer byteBufferData = ByteBuffer.wrap( data );
826845
synchronized( clients ) {
827846
for( WebSocket client : clients ) {
828847
if( client != null ) {
829848
Draft draft = client.getDraft();
830849
if( !draftFrames.containsKey( draft ) ) {
831-
List<Framedata> frames = draft.createFrames( byteBufferData, false );
850+
List<Framedata> frames = draft.createFrames( data, false );
832851
draftFrames.put( draft, frames );
833852
}
834853
try {

0 commit comments

Comments
 (0)