I am not actually sure that I understand your question exactly, but I will try to help. So you want to have connection client/server for infinite amount of time? So try making both the server client and the client itself as threads and then put the tread in a loop. Try this sample.
connection = new Socket("IP",PORT);
input = new DataInputStream(connection.getInputStream());
output = new DataOutputStream(connection.getOutputStream());
new Thread(new Runnable() {
public void run(){
while(true){
try
{
System.out.println(">>" + input.readUTF());
}
catch(Exception e){
try
{
input.close();
output.close();
connection.close();
}
catch(Exception e2)
{}
}
}
}
}).start();
Scanner scan = new Scanner(System.in);
while(true)
{
String data = scan.nextLine();
output.writeUTF(data);
}
This is the code for the client. You must also have ClienT Service thread that accepts all the data and sends back info! Hope I was helpful, because I am not really sure I understood the question correctly. Good Luck!