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