package clientsockettcp;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
public class ClientSocketTCP {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
Socket s = null;
try {
int serverPort = 8000;
s = new Socket(args[1], serverPort);
DataInputStream in = new DataInputStream(s.getInputStream());
DataOutputStream out = new DataOutputStream(s.getOutputStream());
out.writeUTF(args[0]);
String data = in.readUTF();
System.out.println("Received: " + data);
} catch (UnknownHostException e) {
System.out.println("Sock:" + e.getMessage());
} catch (EOFException e) {
System.out.println("EOF:" + e.getMessage());
} catch (IOException e) {
System.out.println("IO:" + e.getMessage());
} finally {
if (s != null) {
try {
s.close();
} catch (IOException e) {
System.out.println("close:" + e.getMessage());
}
}
}// try
}
}
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 1
at clientsockettcp.ClientSocketTCP.main(ClientSocketTCP.java:19)