java.net.BindException: bind failed: EACCES (Permission denied)

今天写android socket编程的时候,遇到一个问题:

代码如下:

new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    mServerSocket = new ServerSocket(mPort);
                    mServer = mServerSocket.accept();

                    mServerOut = new DataOutputStream(mServer.getOutputStream());
                    mServerIn = new DataInputStream(mServer.getInputStream());

                    String contentReceive = mServerIn.readUTF();
                    Message msg = new Message();
                    msg.obj = contentReceive;
                    msg.what = MSG_ON_RECEIVE;
                    mHandler.sendMessage(msg);
                } catch (IOException e) {
                    Log.d(Constants.TAG, "receive---" + e.toString());
                    e.printStackTrace();
                }
            }
        }).start();

报错信息如下:

java.net.BindException: bind failed: EACCES (Permission denied)

解决方法:

1. 没有添加权限:
2. 权限书写不规范:替换
3. 绑定端口号小于1024



你可能感兴趣的:(Android)