bugfix/tratamento de excecao no receive() do udpSocket

This commit is contained in:
GustavoHMDS committed 2026-11-09 11:05:28 -03:00
1 parent acfee89563
commit fb2f4a7c18
2 files changed
+99 -61

No files matched your search

+45 -46
View File
@@ -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">{
&quot;associatedIndex&quot;: 2,
&quot;fromUser&quot;: false
&quot;associatedIndex&quot;: 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">{
&quot;keyToString&quot;: {
&quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;RunOnceActivity.typescript.service.memoryLimit.init&quot;: &quot;true&quot;,
&quot;codeWithMe.voiceChat.enabledByDefault&quot;: &quot;false&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/Gustavo/OneDrive/Documentos/Faculdade/2026_2/Monitoria/pitiupi&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;project.structure.last.edited&quot;: &quot;Project&quot;,
&quot;project.structure.proportion&quot;: &quot;0.0&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.0&quot;,
&quot;run.code.analysis.last.selected.profile&quot;: &quot;pProject Default&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;
<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>
+54 -15
View File
@@ -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,35 +164,73 @@ 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;
Logger.getLogger(SocketUDP.class.getName())
.log(Level.SEVERE, "Erro ao receber datagrama UDP", ex);
break;
} catch (RuntimeException ex) {
Logger.getLogger(SocketUDP.class.getName())
.log(Level.WARNING, "Falha ao processar datagrama UDP", ex);
}
}
}
Object coreMessage = tryParseCoreUdpMessage(msgPacket.getData());
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, msgPacket.getAddress());
continue;
connectionManager.receiveHeartbeat(
heartbeat,
packet.getAddress()
);
return;
}
if (coreMessage instanceof GoodbyeMessage goodbye) {
connectionManager.receiveGoodbye(goodbye);
continue;
}
if (coreMessage instanceof SessionInviteMessage invite) {
connectionManager.receiveSessionInvite(invite);
continue;
return;
}
pluginManager.handleMessage(msgPacket.getData());
if (coreMessage instanceof SessionInviteMessage invite) {
connectionManager.receiveSessionInvite(invite);
return;
}
pluginManager.handleMessage(data);
}
/**
@@ -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);
}
}