黑马程序员技术交流社区

标题: 为什么会报错啊?求大神 [打印本页]

作者: 18573626921    时间: 2016-5-12 00:39
标题: 为什么会报错啊?求大神
package com.heima.lianxi;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Lianxi6 {

        /**
         * @param args
         * @throws Exception
         */
        public static void main(String[] args) throws Exception {
                        ServerSocket ss =new ServerSocket(54321);
                        System.out.println("服务器启动,绑定54321");
                        while (true){
                        final Socket socket= ss.accept();
                        new Thread(){
                                public void run(){
                        try {
                                BufferedReader br =new BufferedReader(new InputStreamReader(socket.getInputStream()));
                                PrintStream ps =new PrintStream(socket.getOutputStream());
                                System.out.println(new StringBuffer(br.readLine()).reverse().toString());
                               
                                socket.close();
                        } catch (IOException e) {
                               
                                e.printStackTrace();
                        }
                                }
                        }.start();
                       
                }
        }

}




Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind
        at java.net.DualStackPlainSocketImpl.bind0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
        at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
        at java.net.PlainSocketImpl.bind(Unknown Source)
        at java.net.ServerSocket.bind(Unknown Source)
        at java.net.ServerSocket.<init>(Unknown Source)
        at java.net.ServerSocket.<init>(Unknown Source)
        at com.heima.lianxi.Lianxi6.main(Lianxi6.java:17)

作者: ypenghui    时间: 2016-5-12 00:53
BindException是端口被占用了,貌似你运行了多次;或者这个端口号被其他程序占用了




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2