@@ -60,7 +60,7 @@ public WebSocketServer() throws UnknownHostException {
6060 /**
6161 * Creates a WebSocketServer that will attempt to listen on port
6262 * <var>port</var>.
63- *
63+ *
6464 * @param port
6565 * The port number this server should listen on.
6666 */
@@ -71,7 +71,7 @@ public WebSocketServer( InetSocketAddress address ) {
7171 /**
7272 * Creates a WebSocketServer that will attempt to listen on port <var>port</var>,
7373 * and comply with <tt>Draft</tt> version <var>draft</var>.
74- *
74+ *
7575 * @param port
7676 * The port number this server should listen on.
7777 * @param draft
@@ -99,7 +99,7 @@ public void start() {
9999 * Closes all connected clients sockets, then closes the underlying
100100 * ServerSocketChannel, effectively killing the server socket thread and
101101 * freeing the port the server was bound to.
102- *
102+ *
103103 * @throws IOException
104104 * When socket related I/O errors occur.
105105 */
@@ -114,10 +114,10 @@ public void stop() throws IOException {
114114
115115 /**
116116 * Sends <var>text</var> to all currently connected WebSocket clients.
117- *
117+ *
118118 * @param text
119119 * The String to send across the network.
120- * @throws IOException
120+ * @throws InterruptedException
121121 * When socket related I/O errors occur.
122122 */
123123 public void sendToAll ( String text ) throws InterruptedException {
@@ -126,10 +126,24 @@ public void sendToAll( String text ) throws InterruptedException {
126126 }
127127 }
128128
129+ /**
130+ * Sends <var>data</var> to all currently connected WebSocket clients.
131+ *
132+ * @param data
133+ * The Byte-array of data to send across the network.
134+ * @throws InterruptedException
135+ * When socket related I/O errors occur.
136+ */
137+ public void sendToAll ( byte [] data ) throws InterruptedException {
138+ for ( WebSocket c : this .connections ) {
139+ c .send ( data );
140+ }
141+ }
142+
129143 /**
130144 * Sends <var>text</var> to all currently connected WebSocket clients,
131145 * except for the specified <var>connection</var>.
132- *
146+ *
133147 * @param connection
134148 * The {@link WebSocket} connection to ignore.
135149 * @param text
@@ -149,10 +163,33 @@ public void sendToAllExcept( WebSocket connection, String text ) throws Interrup
149163 }
150164 }
151165
166+ /**
167+ * Sends <var>data</var> to all currently connected WebSocket clients,
168+ * except for the specified <var>connection</var>.
169+ *
170+ * @param connection
171+ * The {@link WebSocket} connection to ignore.
172+ * @param data
173+ * The Byte-Array of data to send to every connection except <var>connection</var>.
174+ * @throws InterruptedException
175+ * When socket related I/O errors occur.
176+ */
177+ public void sendToAllExcept ( WebSocket connection , byte [] data ) throws InterruptedException {
178+ if ( connection == null ) {
179+ throw new NullPointerException ( "'connection' cannot be null" );
180+ }
181+
182+ for ( WebSocket c : this .connections ) {
183+ if ( !connection .equals ( c ) ) {
184+ c .send ( data );
185+ }
186+ }
187+ }
188+
152189 /**
153190 * Sends <var>text</var> to all currently connected WebSocket clients,
154191 * except for those found in the Set <var>connections</var>.
155- *
192+ *
156193 * @param connections
157194 * @param text
158195 * @throws IOException
@@ -170,6 +207,27 @@ public void sendToAllExcept( Set<WebSocket> connections, String text ) throws In
170207 }
171208 }
172209
210+ /**
211+ * Sends <var>data</var> to all currently connected WebSocket clients,
212+ * except for those found in the Set <var>connections</var>.
213+ *
214+ * @param connections
215+ * @param data
216+ * @throws InterruptedException
217+ * When socket related I/O errors occur.
218+ */
219+ public void sendToAllExcept ( Set <WebSocket > connections , byte [] data ) throws InterruptedException {
220+ if ( connections == null ) {
221+ throw new NullPointerException ( "'connections' cannot be null" );
222+ }
223+
224+ for ( WebSocket c : this .connections ) {
225+ if ( !connections .contains ( c ) ) {
226+ c .send ( data );
227+ }
228+ }
229+ }
230+
173231 /**
174232 * Returns a WebSocket[] of currently connected clients.
175233 *
0 commit comments