public Handle(MulticastAddress localAddress) throws IOException { this.localAddress = localAddress; this.socket = new MulticastSocket(new InetSocketAddress(localAddress.getGroupAddress(), localAddress.getBindPort())); this.groupAddress = new InetSocketAddress(localAddress.getGroupAddress(), 0); this.device = localAddress.getDevice(); }
private ResourceAddress createResourceAddress(MulticastAddress multicastAddress, String nextProtocol) { String transportName = getTransportName(); InetAddress inetAddress = multicastAddress.getGroupAddress(); String hostAddress = inetAddress.getHostAddress(); String addressFormat = (inetAddress instanceof Inet6Address) ? "%s://[%s]:%s" : "%s://%s:%s"; int port = multicastAddress.getBindPort(); String transport = format(addressFormat, transportName, hostAddress, port); return resourceAddressFactory.newResourceAddress(transport, nextProtocol); }
InetAddress groupAddress = remoteMulticastAddress.getGroupAddress(); NetworkInterface device = remoteMulticastAddress.getDevice(); int bindPort = remoteMulticastAddress.getBindPort(); int uniqueId = nextId.getAndIncrement(); MulticastAddress localMulticastAddress = new MulticastAddress(groupAddress, device, bindPort, uniqueId);
@Override public String toString() { if (uniqueId != -1) { return String.format("mcp://%s:%d on %s (%d)", groupAddress.getHostAddress(), getBindPort(), device.getName(), uniqueId); } else { return String.format("mcp://%s:%d on %s", groupAddress.getHostAddress(), getBindPort(), device.getName()); } } }
@Override public MulticastAddress createSocketAddress(ResourceAddress address) { URI location = address.getResource(); String host = location.getHost(); int port = location.getPort(); String userInfo = location.getUserInfo(); if (host == null) { throw new IllegalArgumentException("Missing host: " + location); } if (port == -1) { throw new IllegalArgumentException("Missing port: " + location); } InetAddress groupAddress = (userInfo != null) ? getByName(userInfo) : getByName(host); NetworkInterface networkInterface = null; if (address instanceof UdpResourceAddress) { networkInterface = ((UdpResourceAddress) address).getUpdInterface(); } if (networkInterface == null) { throw new IllegalArgumentException("Missing networkInterface: " + networkInterface); } return new MulticastAddress(groupAddress, networkInterface, port); }
if (remoteAddress.equals(dispatchSession.getRemoteAddress())) { dispatchSession.close(true);
public ConnectFuture connect(SocketAddress localAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer) { MulticastAddress multicastAddress = (MulticastAddress) localAddress; String uri = format("udp://%s:%d", multicastAddress.getGroupAddress().getHostAddress(), multicastAddress.getBindPort()); ResourceAddress resourceAddress = resourceAddressFactory.newResourceAddress(uri); final MulticastSession newSession = new MulticastSession(MulticastConnectorImpl.this, processor, socket, resourceAddress, remoteAddress); DefaultConnectFuture connectFuture = new DefaultConnectFuture(); initSession(newSession, connectFuture, sessionInitializer); newSession.getProcessor().add(newSession); dispatchSessions.add(newSession); newSession.getCloseFuture().addListener(new IoFutureListener<CloseFuture>() { @Override public void operationComplete(CloseFuture future) { dispatchSessions.remove(newSession); } }); return connectFuture; }
public Handle(MulticastAddress remoteAddress) throws IOException { this.remoteAddress = remoteAddress; this.socket = new MulticastSocket(new InetSocketAddress(remoteAddress.getGroupAddress(), remoteAddress.getBindPort())); this.groupAddress = new InetSocketAddress(remoteAddress.getGroupAddress(), 0); this.device = remoteAddress.getDevice(); this.dispatchSessions = new ConcurrentHashSet<>(); }