refactored UDPThreadedNetwork
This commit is contained in:
parent
52ab728404
commit
868364a0ca
4 changed files with 53 additions and 60 deletions
|
|
@ -55,7 +55,7 @@ public class MulticastDNSClient extends ThreadedUDPNetwork implements ThreadedUD
|
|||
|
||||
|
||||
public MulticastDNSClient() throws IOException {
|
||||
super(null, MDNS_MULTICAST_ADDR, MDNS_MULTICAST_PORT);
|
||||
super(MDNS_MULTICAST_ADDR, MDNS_MULTICAST_PORT);
|
||||
setThread( this );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ public class SSDPClient extends ThreadedUDPNetwork implements ThreadedUDPNetwork
|
|||
* @throws IOException
|
||||
*/
|
||||
public SSDPClient() throws IOException{
|
||||
super(null);
|
||||
super.setThread(this);
|
||||
|
||||
services_st = new HashMap<>();
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public class SSDPServer extends ThreadedUDPNetwork implements ThreadedUDPNetwork
|
|||
|
||||
|
||||
public SSDPServer() throws IOException{
|
||||
super( null, SSDP_MULTICAST_ADDR, SSDP_PORT );
|
||||
super( SSDP_MULTICAST_ADDR, SSDP_PORT );
|
||||
super.setThread( this );
|
||||
|
||||
services = new HashMap<String, SSDPServiceInfo>();
|
||||
|
|
|
|||
16
src/zutil/net/threaded/ThreadedUDPNetwork.java
Normal file → Executable file
16
src/zutil/net/threaded/ThreadedUDPNetwork.java
Normal file → Executable file
|
|
@ -50,13 +50,11 @@ public class ThreadedUDPNetwork extends Thread{
|
|||
/**
|
||||
* Creates a new unicast Client instance of the class
|
||||
*
|
||||
* @param thread is the class that will handle incoming packets
|
||||
* @throws SocketException
|
||||
*/
|
||||
public ThreadedUDPNetwork(ThreadedUDPNetworkThread thread) throws SocketException{
|
||||
public ThreadedUDPNetwork() throws SocketException{
|
||||
this.type = UDPType.UNICAST;
|
||||
this.port = -1;
|
||||
setThread( thread );
|
||||
|
||||
socket = new DatagramSocket();
|
||||
}
|
||||
|
|
@ -64,14 +62,12 @@ public class ThreadedUDPNetwork extends Thread{
|
|||
/**
|
||||
* Creates a new unicast Server instance of the class
|
||||
*
|
||||
* @param thread is the class that will handle incoming packets
|
||||
* @param port is the port that the server should listen to
|
||||
* @throws SocketException
|
||||
*/
|
||||
public ThreadedUDPNetwork(ThreadedUDPNetworkThread thread, int port) throws SocketException{
|
||||
public ThreadedUDPNetwork(int port) throws SocketException{
|
||||
this.type = UDPType.UNICAST;
|
||||
this.port = port;
|
||||
setThread( thread );
|
||||
|
||||
socket = new DatagramSocket( port );
|
||||
}
|
||||
|
|
@ -79,19 +75,17 @@ public class ThreadedUDPNetwork extends Thread{
|
|||
/**
|
||||
* Creates a new multicast Server instance of the class
|
||||
*
|
||||
* @param thread is the class that will handle incoming packets
|
||||
* @param port is the port that the server should listen to
|
||||
* @param multicast_addr is the multicast address that the server will listen on
|
||||
* @param multicastAddr is the multicast address that the server will listen on
|
||||
* @throws IOException
|
||||
*/
|
||||
public ThreadedUDPNetwork(ThreadedUDPNetworkThread thread, String multicast_addr, int port ) throws IOException{
|
||||
public ThreadedUDPNetwork(String multicastAddr, int port ) throws IOException{
|
||||
this.type = UDPType.MULTICAST;
|
||||
this.port = port;
|
||||
setThread( thread );
|
||||
|
||||
// init udp socket
|
||||
MulticastSocket msocket = new MulticastSocket( port );
|
||||
InetAddress group = InetAddress.getByName( multicast_addr );
|
||||
InetAddress group = InetAddress.getByName( multicastAddr );
|
||||
msocket.joinGroup( group );
|
||||
|
||||
socket = msocket;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue