Server程序代码:
package com.java;
import java.io.*;
import java.net.*;public class Server{
public static void main(String[] args)
   {
    //提示本程序的用法
   if(args.length!=1){
   System.out.println("程序运行方式:java Server <端口号>");
   return;
   }
   try{
   //获得端口号
   int port=Integer.parseInt(args[0]);
   Server myserver=new Server(port);
   }catch(Exception e){
   e.printStackTrace();
   }
  }
private int port;
//构造方法
public Server(int port){
this.port=port;
start();
}
//处理用户输入的方法
private String process(String line){
return line.toUpperCase();
}
//启动服务
private void start(){
try{
//创建套接字
ServerSocket mySocket =new ServerSocket(port);
//显示连接信息
System.out.println("服务器启动完成,监听端口在"+port+"。");
System.out.println("正在等待客户连接...");
//挂起等待客户的连接请求
Socket connection = mySocket.accept();
//获取读取客户端内容的数据流
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//获取写往客户端内容的数据流,true表示自动刷新
PrintWriter out = new PrintWriter(connection.getOutputStream(),true);
//向客户发送欢迎的提示信息
out.println("你好,服务器连接成功!");
out.println("输入BYE断开与服务器的连接.");
boolean done = false;
while (!done){
//读取客户端内容
String line = in.readLine();
if(line==null)
done=true;
else{
//在服务器端显示从客户端接收的信息
System.out.println("从客户端来的内容:"+line);
//信息处理
String message=process(line);
//向客户端发送消息
out.println("从服务器端口8000发出的内容:"+message);
if (line.trim().equals("BYE"))
done=true;
}
}
//关闭通信信道
connection.close();

}catch(Exception e){
System.out.println(e);
}
}
}Client程序代码:
package com.java;
import java.io.*;
import java.net.*;
public class Client{
public static void main(String[] args)
{
//提示本程序的用法
if(args.length!=2){
System.out.println("程序运行方式:java Client"+"<服务器名称> <端口号>");
return;
}
//获得服务器名称
String host=args[0];
try{
int port=Integer.parseInt(args[1]);
Client myserver=new Client(host,port);
}catch(Exception e){
e.printStackTrace();
}
}
private String host;
private int port;
//构造方法
public Client (String host,int port){
this.host=host;
this.port=port;
connect();
}
//连接方法
private void connect(){
try{
Socket connection;
//连接到服务器的端口指定端口
if(host.equals("localhost"))
connection=new
      Socket(InetAddress.getLocalHost(),port);
      else
      connection=new
      Socket(InetAddress.getByName(host),port);
      //获得键盘输入流
      BufferedReader stdin=new BufferedReader(
       new InputStreamReader(System.in));
       //获得往服务器写内容的数据流
       PrintWriter out=new PrintWriter(
       connection.getOutputStream(),true);
       //获得服务器的输入流
       BufferedReader in =new BufferedReader(
       new InputStreamReader(connection.getInputStream()));
//从服务器获得欢迎信息
System.out.println("服务器信息:"+in.readLine());
System.out.println("服务器信息:"+in.readLine());
//提示用户输入
System.out.print("请输入 > ");
boolean done=false;
while(!done)
{
  //从键盘上读字符串
  String line=stdin.readLine();
  //写向服务端
  out.println(line);
  //如果读到bye,结束循环
  if(line.equalsIgnoreCase("bye"))
  done=true;
  //从服务器读取字符串
  String info=in.readLine();
  //从客户端显示从服务器返回的字符串
  System.out.println("服务器信息:"+info);
  //提示用户输入
  if(!done)
  System.out.print("请输入 > ");
  
}
  //关闭socket
  connection.close();
     
}catch(SecurityException e){
System.out.println("连接服务器时出现安全问题!");

}catch(IOException e){
System.out.println("连接服务器时出现I/O错误!");
}
}
}在编译时没有出现错误,但运行程序时出现了"Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object"的错误,究竟问题出在哪里啊?