为什么会报错 如何解决?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
public class serverThread implements Runnable {
private Socket ss;
private String KehuDuanXinxi=null;
/*private int xianchengxulie;
private String KehuDuanName;
*/
public serverThread(Socket ss) {
this.ss = ss;
}
public void run() {
/*String string="客户端你好";
socketoOutput(string);*/
KehuDuanXinxi = socketoInput();
socketoOutput("sdfe");
System.out.println("接收到服务器信息内容是" + KehuDuanXinxi);
//serverThread ser= new serverThread(ss);
}
private InputStream is=null;
private InputStreamReader isr=null;
private BufferedReader br=null;
public String socketoInput() {
String string=null;
try {
is = ss.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
string = br.readLine();
ss.shutdownInput();
os = ss.getOutputStream();
pw= new PrintWriter(os);
pw.write("服务器说 欢迎你");
pw.flush();
ss.shutdownOutput();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}finally {
try {
if (br!=null)
br.close();
if (isr!=null)
isr.close();
if (is!=null)
is.close();
if (pw!=null)
pw.close();
if(os!=null)
os.close();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
//while((string=br.readLine())!=null){ xmlOutput(string); }
return string;
}
private OutputStream os=null;
private PrintWriter pw=null;
public void socketoOutput(String string) {
try {
os = ss.getOutputStream();
pw = new PrintWriter(os);
pw.write(string);
pw.flush();
ss.shutdownOutput();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} finally {
try {
if (pw!=null)
pw.close();
if(os!=null)
os.close();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
public void xmlInput() {
}
public void xmlOutput(String string) {
}
}
这段代码 会提示Socket is closed报错