My client can send a single request to the server. I want to create some loads by looping the client 20 times, and having 5 clients running. I tried something based on this post, but it didn't work.
My Server
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.Random;
public class MyServer {
public static void main(String[] args) throws IOException {
String jokes[] = {"j1", "j2", "j3"};
ServerSocket socket = new ServerSocket(9000);
while(true){
Socket s = socket.accept();
PrintWriter print = new PrintWriter(s.getOutputStream(), true);
String ip = (InetAddress.getLocalHost().getHostAddress());
print.println(ip+jokes[(int)(Math.random()*(jokes.length-1))]);
s.close();
print.close();
}
}
}
My Client
import java.io.*;
import java.net.*;
public class MyClient{
public static void main(String[]args) throws IOException{
System.out.println(args[0]);
System.out.println(args[1]);
Socket socket = new Socket(args[0], Integer.parseInt(args[1]));
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String message;
while((message = in.readLine()) != null)
{
System.out.println(message);
System.out.println(cnt);
}
socket.close();
}
}
I'm not familiar with java networking programming, any suggestions would be great.