首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

服务器端被客户端访问完以后出现java.io.ioexception,socket问题。

2014-01-26 
异常为:java.io.ioexception客户端代码如下:package package1.socketimport java.net.*import java.io.*

异常为: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.");         

热点排行