//2.[Client.java]
package smssocket;
import java.io.*;
import java.net.*;public class Client {
public static void main(String args[]) {
//args 是main方法的入参(String数组),在这里应该只有一个,是Server 的name地址
try{
if (args.length != 1){
System.out.println("USAGE: java Client servername");
return;
}
String connectto= args[0];//把入参的第0个字符串赋给connectto
Socket connection;if(connectto.equals("localhost")){
connection=new Socket(InetAddress.getLocalHost(),5000);
//建立一个和本机的Socket连接(Server是本机,也就是说Server、Client在一台机器上),端口用5000
//InetAddress类描述IP地址,InetAddress.getLocalHost()得到本地IP地址,返回类型是InetAddress
}
else{
connection=new Socket(InetAddress.getByName(connectto),5000);
//建立一个和指定服务器的Socket连接,端口为5000
//InetAddress.getByName()根据指定名称,找到IP地址
}
DataInputStream input=new DataInputStream(connection.getInputStream());
//得到输入流String info;
info = input.readUTF();
//以Unicode编码从输入流中读取字符串
System.out.println(info);
connection.close();
//关闭Socket连接
}
catch(SecurityException e){
System.out.println("SecurityException when connecting Server!");
}
catch(IOException e){
System.out.println("IOException when connecting Server!");
}
}} 
建议你看代码的时候参考java API文档。