Reputation: 7
This is the application that I have created but I have the following problems:
The client is able to send messages to other client but they also receive the same message as echo. So I would like to just be able to send a message and get a response from all connected parties, but no my own message.
What would it be the best way to handle disconnection from the client or the server.
I'm not asking for an answer (just indication), on how would it be the best way to allow a client to send files.
Upvotes: 1
Views: 70
Reputation: 41
You can try something like this
for (ClientHandler client : Server.activeClients) {
if(client!=this){
client.dos.writeUTF(this.name + "=" + received);
}
}
Upvotes: 0
Reputation: 121
1-) You can check the user in the for clause before send message.
for (ClientHandler client: Server.activeClients) {
if (!client.name.equals(this.name)) {
client.dos.writeUTF(this.name + "=" + received);
}
}
2-) You don't need to use while(true) change it so it can finish when user disconnected.
while (!s.isClosed()) {
3-) First you need to send file name and file size after that you can send file's bytes in the sender. Receivers will take the bytes until reaches to file size and will save it as file with the given name.
Upvotes: 1