project-mirai / mirai-api-http

Mirai HTTP API (console) plugin
GNU Affero General Public License v3.0
1.64k stars 346 forks source link

http显示端口被占用 #739

Closed smilecat2788 closed 11 months ago

smilecat2788 commented 11 months ago

image 不是说这个http和ws可以用同一个端口不会冲突吗,换个端口就正常了 日志: 2023-09-13 12:53:21 I/Mirai HTTP API: **** 2023-09-13 12:53:21 I/reverse-ws adapter: >>> [reverse-ws adapter] is running 2023-09-13 12:53:21 I/MahKtorAdapter[ws]: Autoreload is disabled because the development mode is off. 2023-09-13 12:53:22 I/MahKtorAdapter[ws]: Application started in 0.183 seconds. 2023-09-13 12:53:22 I/MahKtorAdapter[ws]: Responding at http://localhost:8100 2023-09-13 12:53:22 I/ws adapter: >>> [ws adapter] is listening at ws://localhost:8100 2023-09-13 12:53:22 I/MahKtorAdapter[http]: Autoreload is disabled because the development mode is off. 2023-09-13 12:53:22 I/MahKtorAdapter[http]: Application started in 0.415 seconds. 2023-09-13 12:53:22 E/mirai-api-http: kotlinx.coroutines.JobCancellationException: LazyStandaloneCoroutine is cancelling; job=LazyStandaloneCoroutine{Cancelling}@80b6098 kotlinx.coroutines.JobCancellationException: LazyStandaloneCoroutine is cancelling; job=LazyStandaloneCoroutine{Cancelling}@80b6098 Caused by: java.net.BindException: Address already in use at java.base/sun.nio.ch.Net.bind0(Native Method) at java.base/sun.nio.ch.Net.bind(Unknown Source) at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(Unknown Source) at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) at mirai-api-http-2.9.1.mirai2.jar[shared]//io.ktor.network.sockets.ConnectUtilsJvmKt.bind(ConnectUtilsJvm.kt:35) at mirai-api-http-2.9.1.mirai2.jar[shared]//io.ktor.network.sockets.TcpSocketBuilder.bind(TcpSocketBuilder.kt:45) at mirai-api-http-2.9.1.mirai2.jar[shared]//io.ktor.network.sockets.TcpSocketBuilder.bind(TcpSocketBuilder.kt:29) at mirai-api-http-2.9.1.mirai2.jar[shared]//io.ktor.network.sockets.TcpSocketBuilder.bind$default(TcpSocketBuilder.kt:25) at mirai-api-http-2.9.1.mirai2.jar[shared]//io.ktor.server.cio.backend.HttpServerKt$httpServer$acceptJob$1.invokeSuspend(HttpServer.kt:48) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)

2023-09-13 12:53:22 I/mirai-skia-plugin: platform: linux-x64, skia: m110-ad42464-1, skiko: 0.7.58 2023-09-13 12:53:22 E/MahKtorAdapter[http]: java.net.BindException: Address already in use java.net.BindException: Address already in use at java.base/sun.nio.ch.Net.bind0(Native Method) at java.base/sun.nio.ch.Net.bind(Unknown Source) at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(Unknown Source) at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) at mirai-api-http-2.9.1.mirai2.jar[shared]//io.ktor.network.sockets.ConnectUtilsJvmKt.bind(ConnectUtilsJvm.kt:35) at mirai-api-http-2.9.1.mirai2.jar[shared]//io.ktor.network.sockets.TcpSocketBuilder.bind(TcpSocketBuilder.kt:45) at mirai-api-http-2.9.1.mirai2.jar[shared]//io.ktor.network.sockets.TcpSocketBuilder.bind(TcpSocketBuilder.kt:29) at mirai-api-http-2.9.1.mirai2.jar[shared]//io.ktor.network.sockets.TcpSocketBuilder.bind$default(TcpSocketBuilder.kt:25) at mirai-api-http-2.9.1.mirai2.jar[shared]//io.ktor.server.cio.backend.HttpServerKt$httpServer$acceptJob$1.invokeSuspend(HttpServer.kt:48) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)

cssxsh commented 11 months ago

8080 又不是 mirai-api-http 的专属端口,它是很常见的默认端口 其他软件也可能会使用,比如 https://github.com/fuqiuluo/unidbg-fetch-qsign

ryoii commented 11 months ago

这里不属于复用的情况

WebSocket 监听的 localhost:8100 已经成功了,失败的是 Http 的 0.0.0.0:8100 。检查以下本机是否有其他进程占用了 0.0.0.0:8100

如果要测试插件是否可以复用端口,可以先试下 WebSocket 和 Http 都同时换个端口

smilecat2788 commented 11 months ago

好的,我会试试,谢谢

ryoii commented 11 months ago

而且我不太建议你对 0.0.0.0localhost 监听同一个端口。此时访问 localhost127.0.0.1 具体会请求到哪一个套接字似乎不同情况有不同实现

smilecat2788 commented 11 months ago

是的,之前ws和http共用8100端口没有问题,改了veify验证和localhost之后就会报错了,我想在公网环境下访问http做测试用,有个依赖mirahttp的插件是白名单模式,我想写个脚本从http获取所有群号写到那个插件的配置文件里,以此实现所有群都可以用该插件

smilecat2788 commented 11 months ago

问题已经解决,确实是ws和http冲突导致http监听失败,将ws的localhost也改为0.0.0.0即可同时启动 另外mirahttp的文档似乎没有说明请求路径?比如我想获取mira版本应该GET/about ,我看API文档好像只有请求参数和响应的格式,我想获取所有群列表不知道请求路径

ryoii commented 11 months ago

在线文档

这里进去就有的,只有请求参数和响应的格式那部分是不同 adapter 一起用的,所以没有只针对Http的请求路径

smilecat2788 commented 11 months ago

非常感谢