首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打开网页,但无法连接到Websocket。

打开网页,但无法连接到Websocket。
EN

Stack Overflow用户
提问于 2021-05-30 19:55:29
回答 1查看 369关注 0票数 0

我正在使用localhost:8080连接,它生成“登录”页面,但是当我连接时,它会产生“无法连接到WebSocket服务器。请刷新此页面再试一次!”位于main.js第50行。

老实说,我对Spring和这一切都很陌生。我看了很多教程,试图找出为什么有些东西不起作用。它们都会产生同样的错误。我正在运行一个gradle应用程序,我将在下面提供我的build.gradle。我还将尝试显示我的完整控制台日志。

控制台日志- https://gist.github.com/beanbeanjuice/035f8dcd8e5b347eab87558fe713d8c8

会产生一些错误,例如LibraryNotFoundError for org.apache.tomcat.jni,然而,经过一些研究,这似乎是“正常”的行为。

第二个值得注意的错误是用于ClassNotFoundExceptionjava.net.UnixDomainSocketAddress,它在切换到JDK 16时似乎消失了。然而,切换到JDK 16并没有解决这个问题。

这是我的build.grade;

代码语言:javascript
复制
plugins {
    id 'com.github.johnrengelman.shadow' version '7.0.0'
    id 'org.springframework.boot' version '2.5.0'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'application'
}

def versionName

try {
    def result = new groovy.json.JsonSlurper().parseText(file('beta.json').text)
    versionName = result.bot.version
} catch (ignored) {
    versionName = 'v0.0.0'
}

sourceCompatibility = '15'
group 'com.beanbeanjuice'
mainClassName = 'com.beanbeanjuice.main.CafeBot'
version versionName

repositories {

    // Central Maven repository.
    mavenCentral()

    maven {
        url 'https://m2.dv8tion.net/releases'
    }

}

dependencies {

    // JUnit, for Unit Testing
    testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.0-M1'
    testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine'

    // Json Slurper
    implementation group: 'org.codehaus.groovy', name: 'groovy-json', version: '3.0.8'

    // Jetbrains Annotations
    implementation group: 'org.jetbrains', name: 'annotations', version: '21.0.1'

    // Discord JDA, for Discord things
    implementation group: 'net.dv8tion', name: 'JDA', version: '4.2.1_265'

    // Twitch Connections
    implementation group: 'com.github.twitch4j', name: 'twitch4j', version: '1.4.0'

    // Lava Player
    implementation group: 'com.sedmelluq', name: 'lavaplayer', version: '1.3.77'

    // Spotify API
    implementation group: 'se.michaelthelin.spotify', name: 'spotify-web-api-java', version: '6.5.4'

    // JSOUP for Parsing
    implementation group: 'org.jsoup', name: 'jsoup', version: '1.13.1'

    // JSON
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.3'
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.12.3'
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.3'

    // Logback
    implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'

    // SQL Connection
    implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.7.3'

    // Time Stuff (For Birthdays)
    implementation group: 'joda-time', name: 'joda-time', version: '2.10.10'

    // Apple Music/Itunes API
    implementation group: 'be.ceau', name: 'itunes-api', version: '4.6.0'

    // Spring Stuff
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-websocket', version: '2.4.3'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-reactor-netty', version: '2.4.3'
    testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.4.3'

}

test {
    useJUnitPlatform()
}

compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'

我怀疑这与我的电脑有关,但此时我完全迷失了方向。

编辑1:似乎发生了什么事情,导致它得到一个404错误,即使它确实通过浏览器连接。websocket的登陆页面工作,但websocket本身不工作。这是错误;

代码语言:javascript
复制
05-30-2021 16:10:44.984 -0400 http-nio-4002-exec-5                          Rfc6265CookiePr DEBUG  Cookies: Parsing b[]: Webstorm-7aec51c5=4c5a97a9-ed16-42bc-89aa-409f0b675f69; Webstorm-7aec5584=a3831a74-27ec-4566-a79c-66e02fe05627
05-30-2021 16:10:44.984 -0400 http-nio-4002-exec-5                          AuthenticatorBa DEBUG  Security checking request GET /console/info
05-30-2021 16:10:44.984 -0400 http-nio-4002-exec-5                          RealmBase       DEBUG    No applicable constraints defined
05-30-2021 16:10:44.984 -0400 http-nio-4002-exec-5                          AuthenticatorBa DEBUG  Not subject to any constraint
05-30-2021 16:10:44.984 -0400 http-nio-4002-exec-5                          Parameters      DEBUG  Set encoding to UTF-8
05-30-2021 16:10:44.985 -0400 http-nio-4002-exec-5                          Parameters      DEBUG  Decoding query null UTF-8
05-30-2021 16:10:44.985 -0400 http-nio-4002-exec-5                          Parameters      DEBUG  Start processing with input [t=1622405444981]
05-30-2021 16:10:44.985 -0400 http-nio-4002-exec-5                          DispatcherServl DEBUG  GET "/console/info?t=1622405444981", parameters={masked}
05-30-2021 16:10:44.985 -0400 http-nio-4002-exec-5                          SimpleUrlHandle DEBUG  Mapped to ResourceHttpRequestHandler [Classpath [META-INF/resources/], Classpath [resources/], Classpath [static/], Classpath [public/], ServletContext [/]]
05-30-2021 16:10:44.986 -0400 http-nio-4002-exec-5                          ResourceHttpReq DEBUG  Resource not found
05-30-2021 16:10:44.986 -0400 http-nio-4002-exec-5                          DispatcherServl DEBUG  Completed 404 NOT_FOUND
05-30-2021 16:10:44.986 -0400 http-nio-4002-exec-5                          [localhost]     DEBUG  Processing ErrorPage[errorCode=0, location=/error]
05-30-2021 16:10:44.986 -0400 http-nio-4002-exec-5                          DispatcherServl DEBUG  "ERROR" dispatch for GET "/error?t=1622405444981", parameters={masked}
05-30-2021 16:10:44.987 -0400 http-nio-4002-exec-5                          RequestMappingH DEBUG  Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
05-30-2021 16:10:45.002 -0400 http-nio-4002-exec-5                          HttpEntityMetho DEBUG  Using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, application/*+json]
05-30-2021 16:10:45.002 -0400 http-nio-4002-exec-5                          HttpEntityMetho DEBUG  Writing [{timestamp=Sun May 30 16:10:44 EDT 2021, status=404, error=Not Found, path=/console/info}]
05-30-2021 16:10:45.020 -0400 http-nio-4002-exec-5                          DispatcherServl DEBUG  Exiting from "ERROR" dispatch, status 404
05-30-2021 16:10:45.020 -0400 http-nio-4002-exec-5                          [dispatcherServ DEBUG   Disabling the response for further output
05-30-2021 16:10:45.021 -0400 http-nio-4002-exec-5                          Http11InputBuff DEBUG  Before fill(): parsingHeader: [true], parsingRequestLine: [true], parsingRequestLinePhase: [0], parsingRequestLineStart: [0], byteBuffer.position(): [0], byteBuffer.limit(): [0], end: [415]
05-30-2021 16:10:45.021 -0400 http-nio-4002-exec-5                          SocketWrapperBa DEBUG  Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2afef747:org.apache.tomcat.util.net.NioChannel@20069c37:java.nio.channels.SocketChannel[connected local=/127.0.0.1:4002 remote=/127.0.0.1:56600]], Read from buffer: [0]
05-30-2021 16:10:45.021 -0400 http-nio-4002-exec-5                          NioEndpoint     DEBUG  Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2afef747:org.apache.tomcat.util.net.NioChannel@20069c37:java.nio.channels.SocketChannel[connected local=/127.0.0.1:4002 remote=/127.0.0.1:56600]], Read direct from socket: [0]
05-30-2021 16:10:45.021 -0400 http-nio-4002-exec-5                          Http11InputBuff DEBUG  Received []
05-30-2021 16:10:45.021 -0400 http-nio-4002-exec-5                          Http11Processor DEBUG  Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2afef747:org.apache.tomcat.util.net.NioChannel@20069c37:java.nio.channels.SocketChannel[connected local=/127.0.0.1:4002 remote=/127.0.0.1:56600]], Status in: [OPEN_READ], State out: [OPEN]
05-30-2021 16:10:45.021 -0400 http-nio-4002-exec-5                          Http11NioProtoc DEBUG  Pushed Processor [org.apache.coyote.http11.Http11Processor@795e5110]
05-30-2021 16:10:45.021 -0400 http-nio-4002-exec-5                          NioEndpoint     DEBUG  Registered read interest for [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2afef747:org.apache.tomcat.util.net.NioChannel@20069c37:java.nio.channels.SocketChannel[connected local=/127.0.0.1:4002 remote=/127.0.0.1:56600]]

我不知道404为什么会发生。我在做更多的研究,但是,我所尝试的一切还是不起作用。

EN

回答 1

Stack Overflow用户

发布于 2021-05-30 20:29:15

我想通了。我的websocket包必须在相同的包中,或者在我的Main类的子包中。GG。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67765279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档