ServerManager WIP
This commit is contained in:
1 parent
53d7436966
commit
49cf3760a0
12 files changed
+244
-161
No files matched your search
@@ -7,6 +7,7 @@ import pitiupi.application.peeractions.PeerActionBroker;
|
||||
import pitiupi.application.presence.PresenceService;
|
||||
import pitiupi.models.Messages.*;
|
||||
import pitiupi.control.plugins.PluginManager;
|
||||
import pitiupi.net.servers.ServerManager;
|
||||
import pitiupi.net.tcp.SocketTCP;
|
||||
import pitiupi.net.tcp.TcpAttemptListener;
|
||||
import pitiupi.net.tcp.TcpConnectNotice;
|
||||
@@ -29,6 +30,7 @@ public class ConnectionManager {
|
||||
private final PluginManager pluginManager;
|
||||
|
||||
private final HeartbeatManager heartbeatManager;
|
||||
private final ServerManager serverManager;
|
||||
private final PresenceService presenceService;
|
||||
private final PeerActionBroker peerActionBroker;
|
||||
private final InviteInboxService inviteInboxService;
|
||||
@@ -67,6 +69,7 @@ public class ConnectionManager {
|
||||
}
|
||||
|
||||
heartbeatManager = new HeartbeatManager(this);
|
||||
serverManager = new ServerManager(this);
|
||||
peerActionBroker = new PeerActionBroker();
|
||||
inviteInboxService = new InviteInboxService(heartbeatManager);
|
||||
peerActivityInbox = new PeerActivityInbox();
|
||||
@@ -399,9 +402,7 @@ public class ConnectionManager {
|
||||
this.username = userName;
|
||||
}
|
||||
|
||||
public void receiveConnectionRequest(ConnectionRequestMessage message) {
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
public void receiveServerConnection(TcpConnection tcpConnection) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package pitiupi.models.Messages;
|
||||
|
||||
import pitiupi.net.servers.ConnectionData;
|
||||
import pitiupi.net.servers.NetworkData;
|
||||
|
||||
public class ConnectionRequestMessage extends Message {
|
||||
public enum RequestStatus {
|
||||
@@ -10,12 +10,12 @@ public class ConnectionRequestMessage extends Message {
|
||||
}
|
||||
|
||||
final private String receiverId;
|
||||
final private ConnectionData senderData;
|
||||
final private NetworkData senderData;
|
||||
final private RequestStatus requestStatus;
|
||||
|
||||
private ConnectionRequestMessage(
|
||||
String receiverId,
|
||||
ConnectionData senderData,
|
||||
NetworkData senderData,
|
||||
RequestStatus requestStatus
|
||||
) {
|
||||
this.receiverId = receiverId;
|
||||
@@ -25,7 +25,7 @@ public class ConnectionRequestMessage extends Message {
|
||||
|
||||
public static ConnectionRequestMessage pendingRequest(
|
||||
String receiverId,
|
||||
ConnectionData senderData
|
||||
NetworkData senderData
|
||||
) {
|
||||
return new ConnectionRequestMessage(receiverId, senderData, RequestStatus.PENDING);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class ConnectionRequestMessage extends Message {
|
||||
return receiverId;
|
||||
}
|
||||
|
||||
public ConnectionData getSenderData() {
|
||||
public NetworkData getSenderData() {
|
||||
return senderData;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package pitiupi.net.servers;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public record ConnectionData(
|
||||
public record NetworkData(
|
||||
String id,
|
||||
String connectionName,
|
||||
String ownerName,
|
||||
@@ -0,0 +1,24 @@
|
||||
package pitiupi.net.servers;
|
||||
|
||||
public abstract class NetworkEndpoint {
|
||||
protected final NetworkData networkData;
|
||||
protected boolean isOpen;
|
||||
|
||||
NetworkEndpoint(NetworkData networkData) {
|
||||
this.networkData = networkData;
|
||||
|
||||
this.isOpen = true;
|
||||
}
|
||||
|
||||
public NetworkData getData() {
|
||||
return networkData;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
void close() {
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
+27
-26
@@ -1,7 +1,7 @@
|
||||
package pitiupi.control;
|
||||
package pitiupi.net.servers;
|
||||
|
||||
import pitiupi.control.ConnectionManager;
|
||||
import pitiupi.models.Messages.ConnectionRequestMessage;
|
||||
import pitiupi.net.servers.*;
|
||||
import pitiupi.net.tcp.ConnectionFactory;
|
||||
import pitiupi.net.tcp.TcpConnection;
|
||||
import pitiupi.presentation.shell.LocalNetworkInfo;
|
||||
@@ -21,33 +21,35 @@ import java.util.logging.Logger;
|
||||
public class ServerManager {
|
||||
private final ConnectionManager connectionManager;
|
||||
|
||||
private final Map<ConnectionData, UdpServer> udpServers;
|
||||
private final Map<ConnectionData, UdpClient> udpClients;
|
||||
private final Map<NetworkData, UdpServer> udpServers;
|
||||
private final Map<NetworkData, UdpClient> udpClients;
|
||||
|
||||
private final Map<ConnectionData, TcpServer> tcpServers;
|
||||
private final Map<ConnectionData, TcpClient> tcpClients;
|
||||
private final Map<NetworkData, TcpServer> tcpServers;
|
||||
private final Map<NetworkData, TcpClient> tcpClients;
|
||||
|
||||
private static final int HANDSHAKE_TIMEOUT_MS = 1000;
|
||||
|
||||
public static final String SERVER_CONNECTION_ID = "PITIUPI.SERVER.CONNECTION.REQUEST";
|
||||
|
||||
public ServerManager(ConnectionManager connectionManager) {
|
||||
this.connectionManager = connectionManager;
|
||||
|
||||
udpServers = new HashMap<ConnectionData, UdpServer>();
|
||||
udpClients = new HashMap<ConnectionData, UdpClient>();
|
||||
udpServers = new HashMap<NetworkData, UdpServer>();
|
||||
udpClients = new HashMap<NetworkData, UdpClient>();
|
||||
|
||||
tcpServers = new HashMap<ConnectionData, TcpServer>();
|
||||
tcpClients = new HashMap<ConnectionData, TcpClient>();
|
||||
tcpServers = new HashMap<NetworkData, TcpServer>();
|
||||
tcpClients = new HashMap<NetworkData, TcpClient>();
|
||||
}
|
||||
|
||||
public UdpServer getUdpServer(String serverName, String pluginId) {
|
||||
ConnectionData data = new ConnectionData(
|
||||
NetworkData data = new NetworkData(
|
||||
UUID.randomUUID().toString(),
|
||||
serverName,
|
||||
connectionManager.getUserName(),
|
||||
LocalNetworkInfo.bestLocalIpv4(),
|
||||
pluginId,
|
||||
ConnectionData.ConnectionProtocol.UDP,
|
||||
ConnectionData.ConnectionType.SERVER
|
||||
NetworkData.ConnectionProtocol.UDP,
|
||||
NetworkData.ConnectionType.SERVER
|
||||
);
|
||||
|
||||
UdpServer udpServer = new UdpServer(connectionManager, data);
|
||||
@@ -58,16 +60,16 @@ public class ServerManager {
|
||||
public UdpClient getUdpClient(
|
||||
String serverName,
|
||||
String pluginId,
|
||||
ConnectionData serverData) {
|
||||
NetworkData serverData) {
|
||||
|
||||
ConnectionData clientData = new ConnectionData(
|
||||
NetworkData clientData = new NetworkData(
|
||||
UUID.randomUUID().toString(),
|
||||
serverName,
|
||||
connectionManager.getUserName(),
|
||||
LocalNetworkInfo.bestLocalIpv4(),
|
||||
pluginId,
|
||||
ConnectionData.ConnectionProtocol.UDP,
|
||||
ConnectionData.ConnectionType.CLIENT
|
||||
NetworkData.ConnectionProtocol.UDP,
|
||||
NetworkData.ConnectionType.CLIENT
|
||||
);
|
||||
|
||||
if (!doConnectionHandshake(serverData, clientData))
|
||||
@@ -85,8 +87,8 @@ public class ServerManager {
|
||||
}
|
||||
|
||||
private boolean doConnectionHandshake(
|
||||
ConnectionData clientData,
|
||||
ConnectionData serverData
|
||||
NetworkData clientData,
|
||||
NetworkData serverData
|
||||
) throws ServerNotFoundException {
|
||||
ConnectionRequestMessage request =
|
||||
ConnectionRequestMessage.pendingRequest(
|
||||
@@ -98,8 +100,8 @@ public class ServerManager {
|
||||
TcpConnection connection = ConnectionFactory.createConnection(
|
||||
InetAddress.getByName(serverData.ownerAdress()),
|
||||
connectionManager.getPort(),
|
||||
clientData.pluginId(),
|
||||
serverData.pluginId(),
|
||||
SERVER_CONNECTION_ID,
|
||||
SERVER_CONNECTION_ID,
|
||||
true
|
||||
);
|
||||
|
||||
@@ -123,11 +125,6 @@ public class ServerManager {
|
||||
|
||||
return (response.getRequestStatus() == ConnectionRequestMessage.RequestStatus.ACCEPTED);
|
||||
}
|
||||
catch (TimeoutException e) {
|
||||
throw new ServerNotFoundException(
|
||||
serverData.ownerAdress() +
|
||||
" has timed out");
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
Logger.getLogger(ServerManager.class.getName()).log(Level.WARNING, null, e);
|
||||
throw new ServerNotFoundException(
|
||||
@@ -139,4 +136,8 @@ public class ServerManager {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void receiveConnection(TcpConnection tcpConnection) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,51 @@
|
||||
package pitiupi.net.servers;
|
||||
|
||||
public class TcpClient {
|
||||
import pitiupi.net.tcp.TcpConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class TcpClient extends NetworkEndpoint {
|
||||
NetworkData serverData;
|
||||
|
||||
TcpConnection tcpConnection;
|
||||
|
||||
public TcpClient(NetworkData clientData, NetworkData serverData, TcpConnection tcpConnection) {
|
||||
super(clientData);
|
||||
|
||||
this.tcpConnection = tcpConnection;
|
||||
|
||||
this.serverData = serverData;
|
||||
}
|
||||
|
||||
public byte[] getBytes()
|
||||
throws IOException, ClosedConnectionException {
|
||||
|
||||
if (isOpen) return tcpConnection.receive();
|
||||
else throw new ClosedConnectionException("This connection is closed");
|
||||
}
|
||||
|
||||
public void send(byte[] bytes)
|
||||
throws IOException, ClosedConnectionException {
|
||||
|
||||
if (!isOpen) throw new ClosedConnectionException("This connection is closed");
|
||||
|
||||
tcpConnection.send(bytes);
|
||||
}
|
||||
|
||||
public NetworkData getServerData() {
|
||||
return serverData;
|
||||
}
|
||||
|
||||
@Override
|
||||
void close() {
|
||||
try {
|
||||
super.close();
|
||||
tcpConnection.close();
|
||||
} catch (IOException e) {
|
||||
Logger.getLogger(TcpClient.class.getName()).log(Level.WARNING, null, e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,53 @@
|
||||
package pitiupi.net.servers;
|
||||
|
||||
public class TcpServer {
|
||||
import pitiupi.net.tcp.TcpConnection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class TcpServer extends NetworkEndpoint{
|
||||
List<NetworkData> clientsData;
|
||||
Map<String, TcpClient> clientsNetwork;
|
||||
|
||||
private final BlockingQueue<TcpClient> buffer;
|
||||
|
||||
TcpServer(NetworkData serverData) {
|
||||
super(serverData);
|
||||
|
||||
clientsData = new ArrayList<>();
|
||||
clientsNetwork = new ConcurrentHashMap<>();
|
||||
|
||||
buffer = new LinkedBlockingQueue<>();
|
||||
}
|
||||
|
||||
void addClient(NetworkData clientData, TcpClient clientNetwork) throws ClosedConnectionException, InterruptedException {
|
||||
if (!isOpen) throw new ClosedConnectionException("This endpoint is closed");
|
||||
|
||||
clientsData.add(clientData);
|
||||
clientsNetwork.put(clientData.id(), clientNetwork);
|
||||
|
||||
buffer.put(clientNetwork);
|
||||
}
|
||||
|
||||
void removeClient(String clientId) throws ClosedConnectionException, InterruptedException {
|
||||
if (!isOpen) throw new ClosedConnectionException("This endpoint is closed");
|
||||
|
||||
for (NetworkData data: clientsData) {
|
||||
if (data.id().equals(clientId)) {
|
||||
clientsData.remove(data);
|
||||
TcpClient client = clientsNetwork.remove(data.id());
|
||||
|
||||
buffer.remove(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TcpClient getClient() throws InterruptedException {
|
||||
return buffer.take();
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,35 @@
|
||||
package pitiupi.net.servers;
|
||||
|
||||
import pitiupi.control.ConnectionManager;
|
||||
import pitiupi.models.Messages.UdpConnectionMessage;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
public class UdpClient extends NetworkEndpoint {
|
||||
private final NetworkData serverData;
|
||||
|
||||
public class UdpClient {
|
||||
private final ConnectionManager connectionManager;
|
||||
|
||||
private final ConnectionData serverData;
|
||||
private final ConnectionData clientData;
|
||||
private final BlockingQueue<byte[]> buffer;
|
||||
private boolean isOpen;
|
||||
|
||||
private static final int MAX_BUFFER_CAPACITY = 1024;
|
||||
private final UdpNetworkIO udpNetworkIO;
|
||||
|
||||
public UdpClient(
|
||||
ConnectionManager connectionManager,
|
||||
ConnectionData serverData,
|
||||
ConnectionData clientData
|
||||
NetworkData serverData,
|
||||
NetworkData clientData
|
||||
) {
|
||||
this.connectionManager = connectionManager;
|
||||
super(clientData);
|
||||
|
||||
this.udpNetworkIO = new UdpNetworkIO(connectionManager);
|
||||
|
||||
this.serverData = serverData;
|
||||
this.clientData = clientData;
|
||||
|
||||
buffer = new ArrayBlockingQueue<>(MAX_BUFFER_CAPACITY);
|
||||
|
||||
isOpen = true;
|
||||
}
|
||||
|
||||
protected void receiveBytes(byte[] bytes)
|
||||
void receiveBytes(byte[] bytes)
|
||||
throws InterruptedException, ClosedConnectionException {
|
||||
|
||||
if (isOpen) buffer.put(bytes);
|
||||
if (isOpen) udpNetworkIO.receiveBytes(bytes);
|
||||
else throw new ClosedConnectionException("This connection is closed");
|
||||
}
|
||||
|
||||
public byte[] getBytes()
|
||||
throws InterruptedException, ClosedConnectionException {
|
||||
|
||||
if (isOpen) return buffer.take();
|
||||
if (isOpen) return udpNetworkIO.getBytes();
|
||||
else throw new ClosedConnectionException("This connection is closed");
|
||||
}
|
||||
|
||||
@@ -54,34 +38,10 @@ public class UdpClient {
|
||||
|
||||
if (!isOpen) throw new ClosedConnectionException("This connection is closed");
|
||||
|
||||
UdpConnectionMessage message = new UdpConnectionMessage(
|
||||
serverData.id(),
|
||||
clientData.id(),
|
||||
bytes
|
||||
);
|
||||
|
||||
try {
|
||||
InetAddress clientAdress = InetAddress.getByName(clientData.ownerAdress());
|
||||
connectionManager.sendUdpUnicast(message, clientAdress);
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Unknown host exception", e);
|
||||
}
|
||||
udpNetworkIO.send(bytes, networkData.id(), serverData.id(), serverData.ownerAdress());
|
||||
}
|
||||
|
||||
public ConnectionData getServerData() {
|
||||
public NetworkData getServerData() {
|
||||
return serverData;
|
||||
}
|
||||
|
||||
public ConnectionData getClientData() {
|
||||
return clientData;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package pitiupi.net.servers;
|
||||
|
||||
import pitiupi.control.ConnectionManager;
|
||||
import pitiupi.models.Messages.UdpConnectionMessage;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class UdpNetworkIO {
|
||||
private final ConnectionManager connectionManager;
|
||||
|
||||
private final BlockingQueue<byte[]> buffer;
|
||||
private static final int MAX_BUFFER_CAPACITY = 1024;
|
||||
|
||||
public UdpNetworkIO(ConnectionManager connectionManager) {
|
||||
this.connectionManager = connectionManager;
|
||||
this.buffer = new LinkedBlockingQueue<>(MAX_BUFFER_CAPACITY);
|
||||
}
|
||||
|
||||
protected void receiveBytes(byte[] bytes) throws InterruptedException {
|
||||
buffer.put(bytes);
|
||||
}
|
||||
|
||||
public byte[] getBytes() throws InterruptedException {
|
||||
return buffer.take();
|
||||
}
|
||||
|
||||
public void send(byte[] bytes, String senderId, String receiverId, String receiverAdress) {
|
||||
UdpConnectionMessage message = new UdpConnectionMessage(
|
||||
senderId,
|
||||
receiverId,
|
||||
bytes
|
||||
);
|
||||
|
||||
try {
|
||||
InetAddress clientAdress = InetAddress.getByName(receiverAdress);
|
||||
connectionManager.sendUdpUnicast(message, clientAdress);
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Unknown host exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +1,55 @@
|
||||
package pitiupi.net.servers;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import pitiupi.control.ConnectionManager;
|
||||
import pitiupi.models.Messages.UdpConnectionMessage;
|
||||
|
||||
public class UdpServer {
|
||||
private final ConnectionManager connectionManager;
|
||||
public class UdpServer extends NetworkEndpoint{
|
||||
private final List<NetworkData> clientConnections;
|
||||
|
||||
private final ConnectionData serverData;
|
||||
private final List<ConnectionData> clientConnections;
|
||||
|
||||
private final BlockingQueue<byte[]> buffer;
|
||||
private boolean isOpen;
|
||||
|
||||
private static final int MAX_BUFFER_CAPACITY = 1024;
|
||||
private final UdpNetworkIO udpNetworkIO;
|
||||
|
||||
public UdpServer(
|
||||
ConnectionManager connectionManager,
|
||||
ConnectionData serverData
|
||||
NetworkData serverData
|
||||
) {
|
||||
this.connectionManager = connectionManager;
|
||||
super(serverData);
|
||||
|
||||
this.udpNetworkIO = new UdpNetworkIO(connectionManager);
|
||||
|
||||
this.serverData = serverData;
|
||||
this.clientConnections = new ArrayList<>();
|
||||
|
||||
buffer = new ArrayBlockingQueue<>(MAX_BUFFER_CAPACITY);
|
||||
|
||||
isOpen = true;
|
||||
}
|
||||
|
||||
protected void addClient(ConnectionData clientConnection) {
|
||||
void addClient(NetworkData clientConnection) {
|
||||
clientConnections.add(clientConnection);
|
||||
}
|
||||
|
||||
protected void removeClient(ConnectionData clientConnection) {
|
||||
void removeClient(NetworkData clientConnection) {
|
||||
clientConnections.remove(clientConnection);
|
||||
}
|
||||
|
||||
protected void receiveBytes(byte[] bytes)
|
||||
void receiveBytes(byte[] bytes)
|
||||
throws InterruptedException, ClosedConnectionException {
|
||||
|
||||
if (isOpen) buffer.put(bytes);
|
||||
else throw new ClosedConnectionException("This connection is closed");
|
||||
if (isOpen) udpNetworkIO.receiveBytes(bytes);
|
||||
else throw new ClosedConnectionException("This endpoint is closed");
|
||||
}
|
||||
|
||||
public byte[] getBytes()
|
||||
throws InterruptedException, ClosedConnectionException {
|
||||
|
||||
if (isOpen) return buffer.take();
|
||||
if (isOpen) return udpNetworkIO.getBytes();
|
||||
else throw new ClosedConnectionException("This connection is closed");
|
||||
}
|
||||
|
||||
public void sendUnicast(byte[] bytes, ConnectionData clientConnection)
|
||||
public void sendUnicast(byte[] bytes, NetworkData clientConnection)
|
||||
throws ClosedConnectionException {
|
||||
|
||||
if (!isOpen) throw new ClosedConnectionException("This connection is closed");
|
||||
|
||||
UdpConnectionMessage message = new UdpConnectionMessage(
|
||||
serverData.id(),
|
||||
clientConnection.id(),
|
||||
bytes
|
||||
);
|
||||
|
||||
try {
|
||||
InetAddress clientAdress = InetAddress.getByName(clientConnection.ownerAdress());
|
||||
connectionManager.sendUdpUnicast(message, clientAdress);
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Unknown host exception", e);
|
||||
}
|
||||
udpNetworkIO.send(bytes, networkData.id(), clientConnection.id(), clientConnection.ownerAdress());
|
||||
}
|
||||
|
||||
public void sendMulticast(byte[] bytes)
|
||||
@@ -85,35 +57,12 @@ public class UdpServer {
|
||||
|
||||
if (!isOpen) throw new ClosedConnectionException("This connection is closed");
|
||||
|
||||
for (ConnectionData clientConnection : clientConnections) {
|
||||
UdpConnectionMessage message = new UdpConnectionMessage(
|
||||
serverData.id(),
|
||||
clientConnection.id(),
|
||||
bytes
|
||||
);
|
||||
|
||||
try {
|
||||
InetAddress clientAdress = InetAddress.getByName(clientConnection.ownerAdress());
|
||||
connectionManager.sendUdpUnicast(message, clientAdress);
|
||||
} catch (UnknownHostException e) {
|
||||
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Unknown host exception", e);
|
||||
}
|
||||
for (NetworkData clientConnection : clientConnections) {
|
||||
udpNetworkIO.send(bytes, networkData.id(), clientConnection.id(), clientConnection.ownerAdress());
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectionData getServerData() {
|
||||
return serverData;
|
||||
}
|
||||
|
||||
public List<ConnectionData> getClientConnections() {
|
||||
public List<NetworkData> getClientConnections() {
|
||||
return Collections.unmodifiableList(clientConnections);
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import pitiupi.control.plugins.PluginManager;
|
||||
import pitiupi.models.Messages.Message;
|
||||
import pitiupi.models.Messages.InfoMessage;
|
||||
import pitiupi.models.Messages.InfoType;
|
||||
import pitiupi.net.servers.ServerManager;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
@@ -286,6 +287,10 @@ public class SocketTCP extends Thread {
|
||||
return;
|
||||
}
|
||||
|
||||
if (connection.getReceiver().equals(ServerManager.SERVER_CONNECTION_ID)) {
|
||||
|
||||
}
|
||||
|
||||
if (pluginManager.handleConnection(connection, connection.getReceiver())) {
|
||||
privateConnectionReceiver(connection);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class TcpConnection {
|
||||
*
|
||||
* @throws IOException se ocorrer um erro ao fechar o socket
|
||||
*/
|
||||
void close() throws IOException {
|
||||
public void close() throws IOException {
|
||||
socket.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user