接上服务器端程序如下:
package testmt2;
import java.io.*;
import java.net.*;
import java.util.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */public class multiServertestmt {
  private static int port;
 // public static testmtthread1 mt;
 public BufferedReader in;
  public PrintWriter out;
  public String str1=null;
  public String str2=null;
  public String str3=null;
  public String str4=null;
  public String str5=null;
  public String str6=null;
  public String str7=null;
  //public String str8=null;
 // public String str9=null;
  Date now=new Date();
 public String str8=now.toString();
  public multiServertestmt(int port1) {
    this.port=port1;
  }
  public  void newaccept() throws IOException{    ServerSocket s=new ServerSocket(port);
  System.out.println("serversocket"+s);
  try{
     while(true){
       if(s.isBound()==true){
        System.out.println("连接中");
       break;
       }
     try{Socket socket1=s.accept();
    in=new BufferedReader(new InputStreamReader(socket1.getInputStream()));
    out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket1.getOutputStream())),true); String str=in.readLine();
//if(str.equals("end")) break;
System.out.println("echoing:"+str);str1=in.readLine();
System.out.println("second:"+str1);
str2=in.readLine();
System.out.println("third:"+str2);
str3=in.readLine();
System.out.println("fourth:"+str3);
str4=in.readLine();
System.out.println("fourth:"+str4);
str5=in.readLine();
System.out.println("fourth:"+str5);
str6=in.readLine();
System.out.println("fourth:"+str6);
str7=in.readLine();
System.out.println("serven:"+str7);
if((in.readLine()).equalsIgnoreCase("BYE"))
   break;
out.println("ok");
     }catch(IOException e){
       //socket1.close();
      System.out.println(e);
     }
     /*  try{
   new testmtthread1(socket1);
   }catch(IOException e){
       socket1.close();
      }*/
     }
  }finally{
///    in.close();
   // out.close();
    s.close();
  }
  }
 }

解决方案 »

  1.   

    客户端程序如下:package testmt2;import java.io.*;
    import java.net.*;
    import java.util.*;
    /**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class client {
      public static int port;//要连接的服务器端号
    public static String ip;//要连接的服务器地址
     // public Socket socket1;//建立连接对象
    //private ServerSocket serversocket;
    public BufferedReader in;//建立输入输出流
    public PrintWriter out;  public String str1=null;//将流变量初始化
     public String str2=null;
     public String str3=null;
     public String str4=null;
     public String str5=null;
     public String str6=null;
     public String str7=null;
     public String str8=null;
     public String str9=null;
     public String str10=null;
    public String str11=null;//将流变量初始化
     public boolean handle_result=false;
    public client(String IP,int port1) {
        port=port1;
        ip=IP;
      }public void newaccept() throws IOException{
        Socket socket1=new Socket(ip,port);//建立连接
       System.out.println("socket"+socket1);//输出连接对象测试
       if(socket1.isConnected()==true)
      {System.out.println("连接中");
        //break;
       }   try{   in=new BufferedReader(new InputStreamReader(socket1.getInputStream()));//打开输入输出流
       out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket1.getOutputStream())),true);
      /* multiServertestmt newmt=new multiServertestmt(8006);//
       out.println("AODU\n"+newmt.str1+"\n"+newmt.str2+"\n"+
                   "z00859\n"+"01\n"+"00\n"+newmt.str3+"\n"+newmt.str4+"\n"+
                   newmt.str5+"\n"+newmt.str7);
       System.out.println("AODU\n"+newmt.str1+"\n"+newmt.str2+"\n"+
                   "z00859\n"+"01\n"+"00\n"+newmt.str3+"\n"+newmt.str4+"\n"+
                   newmt.str5+"\n"+newmt.str7);
        */  boolean handle_result=true;      str1=in.readLine();
          Thread.sleep(1);
          str2=in.readLine();
          Thread.sleep(1);
          str3=in.readLine();
          Thread.sleep(1);
          str4=in.readLine();
          Thread.sleep(1);
          str5=in.readLine();
          Thread.sleep(1);
          str6=in.readLine();
          Thread.sleep(1);
          str7=in.readLine();
          Thread.sleep(1);
          str8=in.readLine();
          Thread.sleep(1);
          str9=in.readLine();
          Thread.sleep(1);
          str10=in.readLine();
          Thread.sleep(1);
          Date now=new Date();
          str11=now.toString();
          /*   String tmps=null;
          int eid=0;
          while(tmps==null && eid<200){
               tmps=in.readLine();//从SOCKET读取一行
               eid++;
               Thread.sleep(1);
          }
     System.out.println("反馈为:"+tmps);   out.println(newmt.str1+"\n");
       out.println(newmt.str2+"\n");
       out.println("z00859\n");
       out.println("01\n");
       out.println("00\n");
       out.println(newmt.str3+"\n");
       out.println(newmt.str4+"\n");
       out.println(newmt.str5+"\n");
       out.println(newmt.str7);
       *///out.println(newmt.str1);
       //out.println(newmt.str1);   // try{
       //  while(true){
         //Socket socket1=s.accept();
        /* try{   }catch(IOException e){
           socket1.close();
          }*/
    }catch(Exception e){
        System.out.println(e);
        boolean handle=false;
      }
    // catch(UnknownhostException e){  //}
      finally{
      socket1.close();
      in.close();
      out.close();
    }System.out.println("send over");
      } // if(client!=null) client.close();
      //}}
      

  2.   

    数据库连接类如下:package testmt2;import java.io.*;
    import java.net.*;
    import java.util.*;
    /**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class client {
      public static int port;//要连接的服务器端号
    public static String ip;//要连接的服务器地址
     // public Socket socket1;//建立连接对象
    //private ServerSocket serversocket;
    public BufferedReader in;//建立输入输出流
    public PrintWriter out;  public String str1=null;//将流变量初始化
     public String str2=null;
     public String str3=null;
     public String str4=null;
     public String str5=null;
     public String str6=null;
     public String str7=null;
     public String str8=null;
     public String str9=null;
     public String str10=null;
    public String str11=null;//将流变量初始化
     public boolean handle_result=false;
    public client(String IP,int port1) {
        port=port1;
        ip=IP;
      }public void newaccept() throws IOException{
        Socket socket1=new Socket(ip,port);//建立连接
       System.out.println("socket"+socket1);//输出连接对象测试
       if(socket1.isConnected()==true)
      {System.out.println("连接中");
        //break;
       }   try{   in=new BufferedReader(new InputStreamReader(socket1.getInputStream()));//打开输入输出流
       out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket1.getOutputStream())),true);
      /* multiServertestmt newmt=new multiServertestmt(8006);//
       out.println("AODU\n"+newmt.str1+"\n"+newmt.str2+"\n"+
                   "z00859\n"+"01\n"+"00\n"+newmt.str3+"\n"+newmt.str4+"\n"+
                   newmt.str5+"\n"+newmt.str7);
       System.out.println("AODU\n"+newmt.str1+"\n"+newmt.str2+"\n"+
                   "z00859\n"+"01\n"+"00\n"+newmt.str3+"\n"+newmt.str4+"\n"+
                   newmt.str5+"\n"+newmt.str7);
        */  boolean handle_result=true;      str1=in.readLine();
          Thread.sleep(1);
          str2=in.readLine();
          Thread.sleep(1);
          str3=in.readLine();
          Thread.sleep(1);
          str4=in.readLine();
          Thread.sleep(1);
          str5=in.readLine();
          Thread.sleep(1);
          str6=in.readLine();
          Thread.sleep(1);
          str7=in.readLine();
          Thread.sleep(1);
          str8=in.readLine();
          Thread.sleep(1);
          str9=in.readLine();
          Thread.sleep(1);
          str10=in.readLine();
          Thread.sleep(1);
          Date now=new Date();
          str11=now.toString();
          /*   String tmps=null;
          int eid=0;
          while(tmps==null && eid<200){
               tmps=in.readLine();//从SOCKET读取一行
               eid++;
               Thread.sleep(1);
          }
     System.out.println("反馈为:"+tmps);   out.println(newmt.str1+"\n");
       out.println(newmt.str2+"\n");
       out.println("z00859\n");
       out.println("01\n");
       out.println("00\n");
       out.println(newmt.str3+"\n");
       out.println(newmt.str4+"\n");
       out.println(newmt.str5+"\n");
       out.println(newmt.str7);
       *///out.println(newmt.str1);
       //out.println(newmt.str1);   // try{
       //  while(true){
         //Socket socket1=s.accept();
        /* try{   }catch(IOException e){
           socket1.close();
          }*/
    }catch(Exception e){
        System.out.println(e);
        boolean handle=false;
      }
    // catch(UnknownhostException e){  //}
      finally{
      socket1.close();
      in.close();
      out.close();
    }System.out.println("send over");
      } // if(client!=null) client.close();
      //}}
      

  3.   

    totle_operation
    还有operation_1888
    在什么地方啊找不到
      

  4.   

    判断数据库操作类:
    package testmt2;
    import java.net.*;
    import java.io.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class totle_operation {
      String str=null;
     // String sub_str=null;
      public totle_operation() {
      //this.str=str1;
      }
      boolean Is_1888=false;
      public boolean panduan(String str2){    str=str2;
        if(str==null){
        return Is_1888;
        }
        String sub_str=str.substring(5,str.length()+1);
        if(sub_str=="1888"){
        Is_1888=true;
        }
        return Is_1888;
      }  }
    数据库操作类:
    package testmt2;
    import java.sql.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class operation_1888 {
      public operation_1888() {
      }  /*public String getUserInfo(String username,String id)
     {
       String sql = "select username,id from user where username='"+username+"' and id="+id;
       dba db = new dba();
       db.open();
        ResultSet rs = db.executeQueryA(sql);
        try
        {
          if (rs.next()) {
            db.close();
          return "ok";
          }
          else {
            db.close();
            return "no";
          }
        }catch(Exception e){db.close();}
        db.close();
      return "ok";
      }
          */  public void insert (String ICPID,String ICPPass,String SrcTermID,
                          String DesTermID, String MsgFormat,
                          String Msglength, String SendMsg,String  handle_time,
                          boolean handle_result)
     {
       String sql = "insert user_1888(ICPID,ICPPass,SrcTermID,DesTermID,MsgFormat,"+
                    "Msglength,SendMsg,handle_time,handle_result) values('"+
               ICPID+"','"+ICPPass+"','"+SrcTermID+"','"+DesTermID+"','"+MsgFormat+"','"+
               Msglength+"','"+SendMsg+"','"+handle_time+"','"+handle_result+"')";
       dba db1  = new dba();   db1.GetRs(sql);
       //db1.close();
     }
     public void insert (String ICPNAME,String ICPID,String ICPPass,String ServiceID,
                         String FreeType,String FreeCode,String SrcTermID,
                          String DesTermID, String MsgFormat,
                           String SendMsg,String  handle_time,
                          boolean handle_result)
     {
       String sql = "insert master_1888(ICPNAME,ICPID,ICPPass,ServiceID,FreeType,"+
                    "FreeCode,SrcTermID,DesTermID,MsgFormat,"+
                    "SendMsg,handle_time,handle_result) values('"+ICPNAME+"','"+ICPID+"','"+ICPPass+
                    "','"+ServiceID+"','"+FreeType+"','"+FreeCode+"','"+SrcTermID
                    +"','"+DesTermID+"','"+MsgFormat+"','"+SendMsg+"','"+handle_time+
                    "','"+handle_result+"')";
       dba db1  = new dba();   db1.GetRs(sql);
       //db1.close();
     }}
      

  5.   

    我一运行入口类就出现如下错误;
    java.lang.NullPointerException at testmt2.SasterServer.main(SasterServer.java:78)Exception in thread "main" serversocketServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=8006]连接中驱动程序有错误com.microsoft.jdbc.sqlserver.SQLServerDriver查询有错误No suitable driver
      

  6.   

    你没有把三个驱动包放在jdk1.4\lib目录下吧
      

  7.   

    你那来的那个operation_1888里面dba方法啊就是不通
    还少个operation_8886,要不就是你写错
      

  8.   

    你的MSN
    在那个上面我看看不一定会有多少帮助我自己也做过着方面的不过用的Oracle用的是JDBC驱动,没有这样的问题
      

  9.   

    我的机器登不上MSN的好像的端口让TOMCAT给占用了我的QQ是191945951,
      

  10.   

    package testmt2;
    import java.net.*;
    import java.sql.*;
    /**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class operation_8886 {
      public operation_8886() {
      }/*  public String getUserInfo(String username,String id)
      {
        String sql = "select username,id from user where username='"+username+"' and id="+id;
        dba db = new dba();
        db.open();
         ResultSet rs = db.executeQueryA(sql);
         try
         {
           if (rs.next()) {
             db.close();
           return "ok";
           }
           else {
             db.close();
             return "no";
           }
         }catch(Exception e){db.close();}
         db.close();
       return "ok";
       }
     */   public void insert (String ICPID,String ICPPass,String SrcTermID,
                          String DesTermID, String MsgFormat,
                          String Msglength, String SendMsg,String  handle_time,boolean handle_result )
     {
       String sql = "insert user_1888(ICPID,ICPPass,SrcTermID,DesTermID,MsgFormat,"+
                    "Msglength,SendMsg,handle_time,handle_result) values('"+
               ICPID+"','"+ICPPass+"','"+SrcTermID+"','"+DesTermID+"','"+MsgFormat+"','"+
               Msglength+"','"+SendMsg+"','"+handle_time+"','"+handle_result+"')";
       dba db1  = new dba();
      // db1.open();
       db1.GetRs(sql);
       //db1.close();
     }
     public void insert (String ICPNAME,String ICPID,String ICPPass,String ServiceID,
                         String FreeType,String FreeCode,String SrcTermID,
                          String DesTermID, String MsgFormat,
                           String SendMsg,String  handle_time,
                          boolean handle_result)
     {
       String sql = "insert master_1888(ICPNAME,ICPID,ICPPass,ServiceID,FreeType,"+
                    "FreeCode,SrcTermID,DesTermID,MsgFormat,"+
                    "SendMsg,handle_time,handle_result) values('"+ICPNAME+"','"+ICPID+"','"+ICPPass+
                    "','"+ServiceID+"','"+FreeType+"','"+FreeCode+"','"+SrcTermID
                    +"','"+DesTermID+"','"+MsgFormat+"','"+SendMsg+"','"+handle_time+
                    "','"+handle_result+"')";
       dba db1  = new dba();
       //db1.open();
       db1.GetRs(sql);
       //db1.close();
     }
    }