为了账号安全,请及时绑定邮箱和手机立即绑定

java中的网络编程,在使用IO流时有问题

java中的网络编程,在使用IO流时有问题

qq_之恩赫奥丶_0 2016-06-05 16:15:23
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.ServerSocket;import java.net.Socket;public class Server { public static void main(String[] args){ try { ServerSocket ss=new ServerSocket(8888); System.out.println("Reading:"); Socket s=ss.accept(); InputStream is=s.getInputStream(); InputStreamReader isr=new InputStreamReader(is); BufferedReader br=new BufferedReader(isr); String info=null; while((info=br.readLine())!=null){ System.out.println("i am :"+info); } s.shutdownInput(); br.close(); isr.close(); is.close(); s.close(); ss.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}------------------------------------------------------------------------------import java.io.IOException;import java.io.OutputStream;import java.io.PrintWriter;import java.net.Socket;import java.net.UnknownHostException;public class client{ public static void main(String args[]){ try { Socket s=new Socket("localhost",8888); OutputStream os=s.getOutputStream(); PrintWriter pw=new PrintWriter(os); pw.write("ddfdsaf"); pw.flush(); s.shutdownOutput(); pw.close(); os.close(); s.close(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}--------------------------------------------------------------------------------------两个程序如上。再别的电脑运行没有错误,但是我的电脑会报错,内容如下: 到底是怎么回事?Reading:java.net.SocketException: Connection reset at java.net.SocketInputStream.read(Unknown Source) at java.net.SocketInputStream.read(Unknown Source) at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) at sun.nio.cs.StreamDecoder.implRead(Unknown Source) at sun.nio.cs.StreamDecoder.read(Unknown Source) at java.io.InputStreamReader.read(Unknown Source) at java.io.BufferedReader.fill(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at TCP_UDP.ABC.main(ABC.java:20)
查看完整描述

1 回答

?
梦影剑魂

TA贡献66条经验 获得超21个赞

connection reset一般是由于你的SOCKET的关闭了

查看完整回答
1 反对 回复 2016-06-05
  • 1 回答
  • 0 关注
  • 1838 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信