Skip to content

Commit 4d0f4d0

Browse files
committed
Removed the to much specialized methods sendTo* from the WebSocketServer.java.
Users can implement such behavior them self easily.
1 parent 1a36700 commit 4d0f4d0

2 files changed

Lines changed: 14 additions & 58 deletions

File tree

‎example/ChatServer.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,18 @@ public static void main( String[] args ) throws InterruptedException , IOExcepti
7171
public void onError( WebSocket conn, Exception ex ) {
7272
ex.printStackTrace();
7373
}
74+
75+
/**
76+
* Sends <var>text</var> to all currently connected WebSocket clients.
77+
*
78+
* @param text
79+
* The String to send across the network.
80+
* @throws InterruptedException
81+
* When socket related I/O errors occur.
82+
*/
83+
public void sendToAll( String text ) throws InterruptedException {
84+
for( WebSocket c : connections() ) {
85+
c.send( text );
86+
}
87+
}
7488
}

‎src/org/java_websocket/WebSocketServer.java‎

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -112,64 +112,6 @@ public void stop() throws IOException {
112112

113113
}
114114

115-
/**
116-
* Sends <var>text</var> to all currently connected WebSocket clients.
117-
*
118-
* @param text
119-
* The String to send across the network.
120-
* @throws InterruptedException
121-
* When socket related I/O errors occur.
122-
*/
123-
public void sendToAll( String text ) throws InterruptedException {
124-
for( WebSocket c : this.connections ) {
125-
c.send( text );
126-
}
127-
}
128-
129-
/**
130-
* Sends <var>text</var> to all currently connected WebSocket clients,
131-
* except for the specified <var>connection</var>.
132-
*
133-
* @param connection
134-
* The {@link WebSocket} connection to ignore.
135-
* @param text
136-
* The String to send to every connection except <var>connection</var>.
137-
* @throws IOException
138-
* When socket related I/O errors occur.
139-
*/
140-
public void sendToAllExcept( WebSocket connection, String text ) throws InterruptedException {
141-
if( connection == null ) {
142-
throw new NullPointerException( "'connection' cannot be null" );
143-
}
144-
145-
for( WebSocket c : this.connections ) {
146-
if( !connection.equals( c ) ) {
147-
c.send( text );
148-
}
149-
}
150-
}
151-
152-
/**
153-
* Sends <var>text</var> to all currently connected WebSocket clients,
154-
* except for those found in the Set <var>connections</var>.
155-
*
156-
* @param connections
157-
* @param text
158-
* @throws IOException
159-
* When socket related I/O errors occur.
160-
*/
161-
public void sendToAllExcept( Set<WebSocket> connections, String text ) throws InterruptedException {
162-
if( connections == null ) {
163-
throw new NullPointerException( "'connections' cannot be null" );
164-
}
165-
166-
for( WebSocket c : this.connections ) {
167-
if( !connections.contains( c ) ) {
168-
c.send( text );
169-
}
170-
}
171-
}
172-
173115
/**
174116
* Returns a WebSocket[] of currently connected clients.
175117
*

0 commit comments

Comments
 (0)