Skip to content

Commit

Permalink
feat: Server sendPacketToAllClients()
Browse files Browse the repository at this point in the history
  • Loading branch information
LapisBerry committed May 21, 2024
1 parent 6ada5fe commit 0e17f66
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/lapisberry/net/ClientHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lapisberry.net;

import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
Expand Down Expand Up @@ -46,7 +47,7 @@ private void startListeningClientPacket() {
}
}

private void sendPacketToClient(Object packet) {
public void sendPacketToClient(Object packet) {
try {
outputStream.writeObject(packet);
outputStream.flush();
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/lapisberry/net/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ private void startAcceptingClients() {
public void processPacketFromClient(ClientHandler sender, Object packet) {
System.out.println("Processing packet from " + sender.getSocket().getInetAddress().getHostAddress() + ": " + packet);
}

private void sendPacketToAllClients(Object packet) {
for (ClientHandler clientHandler : clientHandlers) {
clientHandler.sendPacketToClient(packet);
}
}
}

0 comments on commit 0e17f66

Please sign in to comment.