I am making a client-server application and am using the following code for the exchange of data b/w the server and clients.
Server's send and receive code:
public void run() {
try {
BufferedReader input = new BufferedReader(new InputStreamReader(socketNew.getInputStream()));
String message=input.readLine();
while(message.length()!=0)
{
for(Socket s:socs) //socs is a list containing all the connected sockets
{
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
writer.write(message);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Client's send method:
private void send_data() {
BufferedWriter writer;
try {
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
writer.write(this.name+textField.getText());
textField.setText("");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Client's receive method:
public void receive_data(){
BufferedReader input;
try {
input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String message=input.readLine();
while(message.length()!=0)
{console(message);}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I am not having any data exchange b/w the server and the clients.Can someone help me please?