SocketException: Failed to create server socket (OS Error: Address already in us

435 阅读1分钟
Start local fair server...
    >>>>>> 0::INFO::2023-06-08 18:18:16.328507::SocketException: Failed to create server socket (OS Error: Address already in use, errno = 48), address = 0.0.0.0, port = 8080
    Unhandled exception:
    SocketException: Failed to create server socket (OS Error: Address already in use, errno = 48), address = 0.0.0.0, port = 8080
    #0      startServer (file:///Users/a99/Documents/Flutter/faircli/FairServer/bin/server.dart:40)
    <asynchronous suspension>
    Process finished with exit code 0
    

查看服务端口列表

方法1:

lsof -i:8080

方法2:

netstat -anp tcp|grep 8080

杀死进程:PID 占用端口号的进程ID

kill -9 PID

但是8080一般是nginx服务,使用ngnix停止命令更合适,清理更彻底:

回忆一下nginx安装:

nginx安装

brew install nginx

Docroot is: /opt/homebrew/var/www

The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo.

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

启动nginx服务

nginx启动,保持后台运行:

To restart nginx after an upgrade:

brew services restart nginx

nginx前台运行的方式启动:

Or, if you don't want/need a background service you can just run:

/opt/homebrew/opt/nginx/bin/nginx -g daemon off;

停止nginx服务

brew services stop nginx

所以解决方法就是: brew services stop nginx