144 |
} |
} |
145 |
|
|
146 |
/** |
/** |
147 |
|
* Sets the local network interface used to send multicast messages |
148 |
|
* |
149 |
|
* @param netIF The local network interface used to send multicast messages |
150 |
|
* |
151 |
|
* @exception SocketException If an error occurs |
152 |
|
* |
153 |
|
* @see MulticastSocket:getNetworkInterface |
154 |
|
* |
155 |
|
* @since 1.4 |
156 |
|
*/ |
157 |
|
public void setNetworkInterface(NetworkInterface netIf) |
158 |
|
throws SocketException |
159 |
|
{ |
160 |
|
if (impl == null) |
161 |
|
throw new SocketException ( |
162 |
|
"MulticastSocket: Cant access socket implementation"); |
163 |
|
|
164 |
|
Enumeration e = netIf.getInetAddresses (); |
165 |
|
|
166 |
|
if (!e.hasMoreElements ()) |
167 |
|
throw new SocketException ("MulticastSocket: Error"); |
168 |
|
|
169 |
|
InetAddress address = (InetAddress) e.nextElement (); |
170 |
|
impl.setOption (SocketOptions.IP_MULTICAST_IF, address); |
171 |
|
} |
172 |
|
|
173 |
|
/** |
174 |
|
* Gets the local network interface which is used to send multicast messages |
175 |
|
* |
176 |
|
* @return The local network interface to send multicast messages |
177 |
|
* |
178 |
|
* @exception SocketException If an error occurs |
179 |
|
* |
180 |
|
* @see MulticastSocket:setNetworkInterface |
181 |
|
* |
182 |
|
* @since 1.4 |
183 |
|
*/ |
184 |
|
public NetworkInterface getNetworkInterface() |
185 |
|
throws SocketException |
186 |
|
{ |
187 |
|
if (impl == null) |
188 |
|
throw new SocketException ( |
189 |
|
"MulticastSocket: Cant access socket implementation"); |
190 |
|
|
191 |
|
InetAddress address = |
192 |
|
(InetAddress) impl.getOption (SocketOptions.IP_MULTICAST_IF); |
193 |
|
NetworkInterface netIf = NetworkInterface.getByInetAddress (address); |
194 |
|
|
195 |
|
return netIf; |
196 |
|
} |
197 |
|
|
198 |
|
/** |
199 |
* Sets the interface to use for multicast packets. |
* Sets the interface to use for multicast packets. |
200 |
* |
* |
201 |
* @param addr The new interface to use |
* @param addr The new interface to use |
290 |
} |
} |
291 |
|
|
292 |
/** |
/** |
293 |
|
* Joins the specified mulitcast group on a specified interface. |
294 |
|
* |
295 |
|
* @param mcastaddr The multicast address to join |
296 |
|
* @param netIf The local network interface to receive the multicast |
297 |
|
* messages on or null to defer the interface set by #setInterface or |
298 |
|
* #setNetworkInterface |
299 |
|
* |
300 |
|
* @exception IOException If an error occurs |
301 |
|
* @exception IllegalArgumentException If address type is not supported |
302 |
|
* @exception SecurityException If a security manager exists and its |
303 |
|
* checkMulticast method doesn't allow the operation |
304 |
|
* |
305 |
|
* @see MulticastSocket:setInterface |
306 |
|
* @see MulticastSocket:setNetworkInterface |
307 |
|
* |
308 |
|
* @since 1.4 |
309 |
|
*/ |
310 |
|
public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) |
311 |
|
throws IOException |
312 |
|
{ |
313 |
|
if (! (mcastaddr instanceof InetSocketAddress)) |
314 |
|
throw new IllegalArgumentException ("SocketAddress type not supported"); |
315 |
|
|
316 |
|
InetSocketAddress tmp = (InetSocketAddress) mcastaddr; |
317 |
|
|
318 |
|
if (! tmp.getAddress ().isMulticastAddress ()) |
319 |
|
throw new IOException ("Not a Multicast address"); |
320 |
|
|
321 |
|
SecurityManager s = System.getSecurityManager (); |
322 |
|
if (s != null) |
323 |
|
s.checkMulticast (tmp.getAddress ()); |
324 |
|
|
325 |
|
impl.joinGroup (mcastaddr, netIf); |
326 |
|
} |
327 |
|
|
328 |
|
/** |
329 |
|
* Leaves the specified mulitcast group on a specified interface. |
330 |
|
* |
331 |
|
* @param mcastaddr The multicast address to leave |
332 |
|
* @param netIf The local networki interface or null to defer to the |
333 |
|
* interface set by setInterface or setNetworkInterface |
334 |
|
* |
335 |
|
* @exception IOException If an error occurs |
336 |
|
* @exception IllegalArgumentException If address type is not supported |
337 |
|
* @exception SecurityException If a security manager exists and its |
338 |
|
* checkMulticast method doesn't allow the operation |
339 |
|
* |
340 |
|
* @see MulticastSocket:setInterface |
341 |
|
* @see MulticastSocket:setNetworkInterface |
342 |
|
* |
343 |
|
* @since 1.4 |
344 |
|
*/ |
345 |
|
public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) |
346 |
|
throws IOException |
347 |
|
{ |
348 |
|
InetSocketAddress tmp = (InetSocketAddress) mcastaddr; |
349 |
|
|
350 |
|
if (! tmp.getAddress ().isMulticastAddress ()) |
351 |
|
throw new IOException ("Not a Multicast address"); |
352 |
|
|
353 |
|
SecurityManager s = System.getSecurityManager (); |
354 |
|
if (s != null) |
355 |
|
s.checkMulticast (tmp.getAddress ()); |
356 |
|
|
357 |
|
impl.leaveGroup (mcastaddr, netIf); |
358 |
|
} |
359 |
|
|
360 |
|
/** |
361 |
* Sends a packet of data to a multicast address with a TTL that is |
* Sends a packet of data to a multicast address with a TTL that is |
362 |
* different from the default TTL on this socket. The default TTL for |
* different from the default TTL on this socket. The default TTL for |
363 |
* the socket is not changed. |
* the socket is not changed. |