A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© liumeng 中级黑马   /  2012-3-14 10:58  /  1791 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


public class TestServer1 {

        /**
         * @param args
         */
        public static void main(String[] args) throws Exception {
                // TODO Auto-generated method stub

                ServerSocket ss=new ServerSocket(5000);
                Socket s=ss.accept();
                InputStream is=s.getInputStream();
                byte[] b=new byte[200];
                int len;
                len=is.read(b, 0,b.length);
                while(-1!=len)
                {
                         System.out.println(new String(b));
                         len=is.read(b, 0,b.length);
                }
          

               
       
        }

}
这是服务端
public class TestClent {

        /**
         * @param args
         */
        public static void main(String[] args) throws Exception {
                // TODO Auto-generated method stub

                Socket s=new Socket("127.0.0.1",5000);
                OutputStream os=s.getOutputStream();
                os.write("asdasd".getBytes());
                os.write("asdasd".getBytes());
        }

}
这是客户端
怎么报
asdasd

4 个回复

倒序浏览
asdasd
asdasd
Exception in thread "main" java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:168)
        at TestServer1.main(TestServer1.java:23)
回复 使用道具 举报
为什么回报SocketInputStream异常
回复 使用道具 举报
是先开的服务端嘛~?
回复 使用道具 举报

是的不知到怎么回事
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马