bugfix/tratamento de excecao no receive() do udpSocket
This commit is contained in:
1 parent
acfee89563
commit
fb2f4a7c18
2 files changed
+105
-67
No files matched your search
Generated
+45
-46
@@ -4,8 +4,9 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="184f7582-9491-4541-9ea8-677e31b83cd6" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/plugins.registry.json" beforeDir="false" afterPath="$PROJECT_DIR$/plugins.registry.json" afterDir="false" />
|
||||
<list default="true" id="62118a1b-608f-4144-b29c-cf46419ca676" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pitiupi/src/pitiupi/net/udp/SocketUDP.java" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/src/pitiupi/net/udp/SocketUDP.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -16,80 +17,78 @@
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 2,
|
||||
"fromUser": false
|
||||
"associatedIndex": 0
|
||||
}</component>
|
||||
<component name="ProjectId" id="3GjM8jvhMxaHpSRoyB7jkVQR4Bc" />
|
||||
<component name="ProjectId" id="3GbOdQKFlKqBjAjqjAv5TRPxr6Z" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
||||
"codeWithMe.voiceChat.enabledByDefault": "false",
|
||||
"git-widget-placeholder": "main",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Users/Gustavo/OneDrive/Documentos/Faculdade/2026_2/Monitoria/pitiupi",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"project.structure.last.edited": "Project",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.0",
|
||||
"run.code.analysis.last.selected.profile": "pProject Default",
|
||||
"settings.editor.selected.configurable": "preferences.lookFeel"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Application.Main.executor": "Run",
|
||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Users/extre/OneDrive/Documentos/Faculdade/2026_02/Monitoria/Pitiupi",
|
||||
"project.structure.last.edited": "Modules",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "preferences.keymap"
|
||||
}
|
||||
}</component>
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\Gustavo\OneDrive\Documentos\Faculdade\2026_2\Monitoria\pitiupi\plugins\ping" />
|
||||
<recent name="C:\Users\Gustavo\OneDrive\Documentos\Faculdade\2026_2\Monitoria\pitiupi\pitiupi\plugins" />
|
||||
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\pitiupi\plugins" />
|
||||
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\plugins\ping" />
|
||||
</key>
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\Gustavo\OneDrive\Documentos\Faculdade\2026_2\Monitoria\pitiupi\plugins\ping" />
|
||||
<recent name="C:\Users\Gustavo\OneDrive\Documentos\Faculdade\2026_2\Monitoria\pitiupi\pitiupi\plugins" />
|
||||
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\plugins\ping" />
|
||||
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\privateChat" />
|
||||
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\privateChat\src" />
|
||||
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\pitiupi\plugins" />
|
||||
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\pitiupi.mpChat\out\META-INF" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration default="true" type="JetRunConfigurationType">
|
||||
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="pitiupi.Main" />
|
||||
<module name="pitiupi" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="pitiupi.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="true" type="KotlinStandaloneScriptRunConfigurationType">
|
||||
<module name="pitiupi" />
|
||||
<option name="filePath" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Application.Main" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
<option value="bundled-jdk-30f59d01ecdd-37e91769500f-intellij.indexing.shared.core-IU-261.26222.65" />
|
||||
<option value="bundled-js-predefined-d6986cc7102b-31caf2ab9e3c-JavaScript-IU-261.26222.65" />
|
||||
<option value="bundled-jdk-9823dce3aa75-bf35d07a577b-intellij.indexing.shared.core-IU-252.28539.149" />
|
||||
</set>
|
||||
</attachedChunks>
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="184f7582-9491-4541-9ea8-677e31b83cd6" name="Changes" comment="" />
|
||||
<created>1784480367533</created>
|
||||
<changelist id="62118a1b-608f-4144-b29c-cf46419ca676" name="Changes" comment="" />
|
||||
<created>1784236888334</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1784480367533</updated>
|
||||
<updated>1784236888334</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -10,6 +10,7 @@ import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.net.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -163,37 +164,75 @@ public class SocketUDP extends Thread {
|
||||
* @throws ClassNotFoundException caso ocorra um erro ao verificar uma
|
||||
* mensagem de heartbeat.
|
||||
*/
|
||||
public void receive() throws UnknownHostException, IOException, ClassNotFoundException {
|
||||
byte[] buf = new byte[256000];
|
||||
public void receive() throws IOException {
|
||||
byte[] buffer = new byte[256000];
|
||||
|
||||
while (running) {
|
||||
DatagramPacket msgPacket = new DatagramPacket(buf, buf.length);
|
||||
DatagramPacket packet = new DatagramPacket(
|
||||
buffer,
|
||||
buffer.length
|
||||
);
|
||||
|
||||
try {
|
||||
multicastSocket.receive(msgPacket);
|
||||
multicastSocket.receive(packet);
|
||||
handlePacket(packet);
|
||||
|
||||
} catch (SocketException ex) {
|
||||
if (!running) {
|
||||
break;
|
||||
}
|
||||
|
||||
Logger.getLogger(SocketUDP.class.getName())
|
||||
.log(Level.SEVERE, "Erro no socket UDP", ex);
|
||||
|
||||
break;
|
||||
|
||||
} catch (IOException ex) {
|
||||
if (!running) {
|
||||
break;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
Object coreMessage = tryParseCoreUdpMessage(msgPacket.getData());
|
||||
if (coreMessage instanceof HeartbeatMessage heartbeat) {
|
||||
connectionManager.receiveHeartbeat(heartbeat, msgPacket.getAddress());
|
||||
continue;
|
||||
}
|
||||
if (coreMessage instanceof GoodbyeMessage goodbye) {
|
||||
connectionManager.receiveGoodbye(goodbye);
|
||||
continue;
|
||||
}
|
||||
if (coreMessage instanceof SessionInviteMessage invite) {
|
||||
connectionManager.receiveSessionInvite(invite);
|
||||
continue;
|
||||
}
|
||||
Logger.getLogger(SocketUDP.class.getName())
|
||||
.log(Level.SEVERE, "Erro ao receber datagrama UDP", ex);
|
||||
|
||||
pluginManager.handleMessage(msgPacket.getData());
|
||||
break;
|
||||
|
||||
} catch (RuntimeException ex) {
|
||||
Logger.getLogger(SocketUDP.class.getName())
|
||||
.log(Level.WARNING, "Falha ao processar datagrama UDP", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePacket(DatagramPacket packet) {
|
||||
byte[] data = Arrays.copyOf(
|
||||
packet.getData(),
|
||||
packet.getLength()
|
||||
);
|
||||
|
||||
Object coreMessage = tryParseCoreUdpMessage(data);
|
||||
|
||||
if (coreMessage instanceof HeartbeatMessage heartbeat) {
|
||||
connectionManager.receiveHeartbeat(
|
||||
heartbeat,
|
||||
packet.getAddress()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (coreMessage instanceof GoodbyeMessage goodbye) {
|
||||
connectionManager.receiveGoodbye(goodbye);
|
||||
return;
|
||||
}
|
||||
|
||||
if (coreMessage instanceof SessionInviteMessage invite) {
|
||||
connectionManager.receiveSessionInvite(invite);
|
||||
return;
|
||||
}
|
||||
|
||||
pluginManager.handleMessage(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tenta identificar os dados recebidos como uma mensagem de heartbeat.
|
||||
*
|
||||
@@ -224,7 +263,7 @@ public class SocketUDP extends Thread {
|
||||
public void run() {
|
||||
try {
|
||||
this.receive();
|
||||
} catch (IOException | ClassNotFoundException ex) {
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(SocketUDP.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user