Bugs corrigidos
This commit is contained in:
1 parent
e5eb4f3f9c
commit
1d9faa93f8
6 files changed
+14
-14
No files matched your search
@@ -91,6 +91,7 @@ public class PrivateChatWindow extends JFrame {
|
|||||||
);
|
);
|
||||||
|
|
||||||
connection.send(message.toByteArray());
|
connection.send(message.toByteArray());
|
||||||
|
receiveMessage(message);
|
||||||
|
|
||||||
messageField.setText("");
|
messageField.setText("");
|
||||||
|
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ public class PublicChatWindow extends JFrame {
|
|||||||
InetAddress ip = InetAddress.getByName(ipField.getText());
|
InetAddress ip = InetAddress.getByName(ipField.getText());
|
||||||
|
|
||||||
pitiupi.sendTcp(msg, ip);
|
pitiupi.sendTcp(msg, ip);
|
||||||
|
receiveMessage(msg);
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.getLogger(
|
Logger.getLogger(
|
||||||
@@ -193,6 +194,7 @@ public class PublicChatWindow extends JFrame {
|
|||||||
InetAddress ip = InetAddress.getByName(ipField.getText());
|
InetAddress ip = InetAddress.getByName(ipField.getText());
|
||||||
|
|
||||||
pitiupi.sendUdpUnicast(msg, ip);
|
pitiupi.sendUdpUnicast(msg, ip);
|
||||||
|
receiveMessage(msg);
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.getLogger(
|
Logger.getLogger(
|
||||||
|
|||||||
@@ -84,6 +84,12 @@ public class MultiProtocolChat extends Plugin {
|
|||||||
@Override
|
@Override
|
||||||
public boolean receiveBytes(TcpConnection connection, byte[] bytes) {
|
public boolean receiveBytes(TcpConnection connection, byte[] bytes) {
|
||||||
MpChatMessage mpChatMessage = parseMessage(bytes);
|
MpChatMessage mpChatMessage = parseMessage(bytes);
|
||||||
|
if (mpChatMessage == null) {
|
||||||
|
System.out.println("Invalid message received");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else System.out.println(mpChatMessage.getMessage());
|
||||||
|
|
||||||
privateChatController.receiveMessage(connection, mpChatMessage);
|
privateChatController.receiveMessage(connection, mpChatMessage);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,8 +61,9 @@ public class PluginManager {
|
|||||||
|
|
||||||
private Plugin getPlugin(String pluginId) {
|
private Plugin getPlugin(String pluginId) {
|
||||||
for (LoadedPlugin loadedPlugin : loadedPlugins) {
|
for (LoadedPlugin loadedPlugin : loadedPlugins) {
|
||||||
if (loadedPlugin.getPlugin().getIdentifier().equals(pluginId))
|
if (loadedPlugin.getPlugin().getIdentifier().equals(pluginId)) {
|
||||||
return loadedPlugin.getPlugin();
|
return loadedPlugin.getPlugin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -80,7 +81,7 @@ public class PluginManager {
|
|||||||
|
|
||||||
plugin.receivePrivateConnection(connection);
|
plugin.receivePrivateConnection(connection);
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleDisconnection(TcpConnection connection, String receiverId) {
|
public void handleDisconnection(TcpConnection connection, String receiverId) {
|
||||||
@@ -117,7 +118,6 @@ public class PluginManager {
|
|||||||
ServiceLoader<Plugin> serviceLoader = ServiceLoader.load(Plugin.class, classLoader);
|
ServiceLoader<Plugin> serviceLoader = ServiceLoader.load(Plugin.class, classLoader);
|
||||||
|
|
||||||
for (Plugin plugin : serviceLoader) {
|
for (Plugin plugin : serviceLoader) {
|
||||||
System.out.println("Loading: " + plugin.getName());
|
|
||||||
LoadedPlugin loadedPlugin = new LoadedPlugin(plugin, classLoader);
|
LoadedPlugin loadedPlugin = new LoadedPlugin(plugin, classLoader);
|
||||||
|
|
||||||
plugin.createPlugin(pitiupi);
|
plugin.createPlugin(pitiupi);
|
||||||
|
|||||||
@@ -66,8 +66,6 @@ public class SocketTCP extends Thread {
|
|||||||
try {
|
try {
|
||||||
serverSocket = new ServerSocket(connectionManager.getPort());
|
serverSocket = new ServerSocket(connectionManager.getPort());
|
||||||
address = InetAddress.getByName(InetAddress.getLocalHost().getHostAddress());
|
address = InetAddress.getByName(InetAddress.getLocalHost().getHostAddress());
|
||||||
if (address != null) System.out.println("SocketTCP: "+ address);
|
|
||||||
else System.out.println("Adress: Null");
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
System.out.println("There is no socket connection. Sorry.");
|
System.out.println("There is no socket connection. Sorry.");
|
||||||
System.out.println(ex.toString());
|
System.out.println(ex.toString());
|
||||||
@@ -262,7 +260,6 @@ public class SocketTCP extends Thread {
|
|||||||
* @param connection conexão cujo fluxo de entrada será processado.
|
* @param connection conexão cujo fluxo de entrada será processado.
|
||||||
*/
|
*/
|
||||||
private void startReceiver(TcpConnection connection) {
|
private void startReceiver(TcpConnection connection) {
|
||||||
System.out.println("Starting TCP connection receiver.");
|
|
||||||
|
|
||||||
if (!connection.isPrivate()) {
|
if (!connection.isPrivate()) {
|
||||||
publicConnectionReceiver(connection);
|
publicConnectionReceiver(connection);
|
||||||
@@ -275,7 +272,6 @@ public class SocketTCP extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pluginManager.handleConnection(connection, connection.getReceiver())) {
|
if (pluginManager.handleConnection(connection, connection.getReceiver())) {
|
||||||
System.out.println("Private connection receiver established.");
|
|
||||||
privateConnectionReceiver(connection);
|
privateConnectionReceiver(connection);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -351,7 +347,6 @@ public class SocketTCP extends Thread {
|
|||||||
while (running) {
|
while (running) {
|
||||||
try {
|
try {
|
||||||
byte[] message = connection.receive();
|
byte[] message = connection.receive();
|
||||||
System.out.println("Um plugin recebeu uma mensagem");
|
|
||||||
InfoMessage sysMessage = InfoMessage.parseSystemInfo(message);
|
InfoMessage sysMessage = InfoMessage.parseSystemInfo(message);
|
||||||
|
|
||||||
if (sysMessage == null) {
|
if (sysMessage == null) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.io.IOException;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representa uma conexão TCP ativa com um peer remoto.
|
* Representa uma conexão TCP ativa com um peer remoto.
|
||||||
@@ -40,8 +41,6 @@ public class TcpConnection {
|
|||||||
this.input = new DataInputStream(socket.getInputStream());
|
this.input = new DataInputStream(socket.getInputStream());
|
||||||
this.output = new DataOutputStream(socket.getOutputStream());
|
this.output = new DataOutputStream(socket.getOutputStream());
|
||||||
this.address = socket.getInetAddress();
|
this.address = socket.getInetAddress();
|
||||||
if (address != null) System.out.println("TcpConnection: " + address);
|
|
||||||
else System.out.println("Adress: Null");
|
|
||||||
this.lastActivity = System.currentTimeMillis();
|
this.lastActivity = System.currentTimeMillis();
|
||||||
this.timeout = 300_000; // 5 minutos
|
this.timeout = 300_000; // 5 minutos
|
||||||
}
|
}
|
||||||
@@ -60,8 +59,6 @@ public class TcpConnection {
|
|||||||
output.write(message);
|
output.write(message);
|
||||||
output.flush();
|
output.flush();
|
||||||
updateLastActivity();
|
updateLastActivity();
|
||||||
|
|
||||||
System.out.println("TcpConnection enviou uma mensagem de tamanho: " + message.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,12 +74,11 @@ public class TcpConnection {
|
|||||||
byte[] receive() throws IOException {
|
byte[] receive() throws IOException {
|
||||||
int length = input.readInt();
|
int length = input.readInt();
|
||||||
|
|
||||||
System.out.println("TcpConnection recebeu uma mensagem de tamanho: " + length);
|
|
||||||
|
|
||||||
if (length < 0) throw new IOException("Invalid message length.");
|
if (length < 0) throw new IOException("Invalid message length.");
|
||||||
|
|
||||||
byte[] message = input.readNBytes(length);
|
byte[] message = input.readNBytes(length);
|
||||||
|
|
||||||
|
|
||||||
if (message.length != length) {
|
if (message.length != length) {
|
||||||
throw new IOException("Connection closed before receiving the complete message.");
|
throw new IOException("Connection closed before receiving the complete message.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user