异常为:java.io.ioexception
客户端代码如下:
package package1.socket;
import java.net.*;
import java.io.*;
import java.util.*;
public class C_Scoket {
Socket C_S;
BufferedReader br;
PrintWriter pw;
String receive;
public static void main(String[] args) {
C_Scoket c_scoket = new C_Scoket();
c_scoket.ConnectToServer();
}
public C_Scoket(){
C_S=null;
br=null;
pw=null;
receive="";
}
public void ConnectToServer(){
try{
C_S = new Socket("localhost", 10000);
br=new BufferedReader(new InputStreamReader(C_S.getInputStream()));
pw=new PrintWriter(C_S.getOutputStream(),true);
System.out.println("Now sends cmd:\"date\" to server……");
pw.println("date");
receive=br.readLine();
if(receive!=null){
System.out.println("The data has been received,that is "+receive);
}
else{
System.out.println("The data is losted.");
}
System.out.println("Now sends cmd:\"Dom\" to server……");
pw.println("dOm");
receive=br.readLine();
if(receive!=null){
System.out.println("The data has been received,that is "+receive);
}
else{
System.out.println("The data is losted.");