I am making a simple chat client for fun, I have the Server/Client working and sending data perfectly. I would like to know how I can send data to selected users. The selecting part I can work out, but I don't know how to send things to the selected IPs. Here is my server so far.
package Server;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
/**
* @class Connect
* @date Feb 25, 2013 10:14:00 PM
* @author Zach
*/
public class Connect { //Server
public static void main(String[] args) throws IOException {
ServerSocket server = new ServerSocket(43595);
while (server.isBound()) {
Socket s = server.accept();
DataOutputStream out = new DataOutputStream(s.getOutputStream());
DataInputStream in = new DataInputStream(s.getInputStream());
int length = in.read();
byte[] data = new byte[length];
in.read(data);
String str = new String(data, "UTF-8");
s.close();
}
}
}
I want to redirect information off of the server to a specific client
Make an array of accepted sockets, in your case from "s" Socket, then you can loop it to find which client to send data to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With