Web套接字在OpenShift上断开连接(使用WildFly 8.2.1)

用户名

我正在使用OpenShift和WildFly 8.2.1 final来实现新的HTML5 websocket。我使用了教程来设置这个项目。

每当我打开MyTest.html时,这就是JavaScript记录的内容:

JS: Server Connected...
JS: Server Disconnected...

服务器连接,然后立即断开连接。为什么?我究竟做错了什么?有什么我想念的吗?

这是模式代码->

serverendpoint.java

package testing;

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/serverendpoint")
public class serverendpoint {
    @OnOpen
    public void handleOpen () {
        System.out.println("JAVA: Client is now connected...");
    }

    @OnMessage
    public String handleMessage (String message) {
        System.out.println("JAVA: Received from client: "+ message);
        String replyMessage = "echo "+ message; 
        System.out.println("JAVA: Send to client: "+ replyMessage);
        return replyMessage;
    }

    @OnClose
    public void handleClose() {
        System.out.println("JAVA: Client is now disconnected...");
    }

    @OnError
    public void handleError (Throwable t) {
        t.printStackTrace();
    }
}

MyTest.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My WS Website</title>
</head>
<body>
    <form>
        <input id="textMessage" type="text">
        <input onclick="sendMessage();" value="Send Message" type="button">
    </form>
    <br>
    <textarea id="messageTextArea" rows="10" cols="50"></textarea>
    <script type="text/javascript">
        var wsUri = "ws://" + document.location.hostname + ":8000" + document.location.pathname + "serverendpoint";
        var webSocket = new WebSocket(wsUri);
        var messageTextArea = document.getElementById("messageTextArea");
        webSocket.onopen = function(message) { processOpen(message);};
        webSocket.onmessage = function(message) { processMessage(message);};
        webSocket.onclose = function(message) { processClose(message);};
        webSocket.onerror = function(message) { processError(message);};
        function processOpen (message) {
            messageTextArea.value += "JS: Server Connected..."+"\n";
        }
        function processMessage(message) {
            messageTextArea.value += "JS: Receive from Server ==> "+message.data+"\n";
        }
        function sendMessage () {
            if (textMessage.value !="close") {
                webSocket.send(textMessage.value);
                messageTextArea.value += "JS: Send to Server ==> "+textMessage.value+"\n";
                textMessage.value="";
            } else webSocket.close();
        }
        function processClose(message) {
            webSocket.send("JS: Client disconnected...")
            messageTextArea.value += "JS: Server Disconnected..."+"\n";
        }
        function processError (message) {
            messageTextArea.value += "JS: error ..."+"\n";
        }
    </script>
</body>
</html>

和pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>testing</groupId>
    <artifactId>testing</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>testing</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

<profiles>
    <profile>
     <!-- When built in OpenShift the 'openshift' profile will be used when invoking mvn. -->
     <!-- Use this profile for any OpenShift specific customization your app will need. -->
     <!-- By default that is to put the resulting archive into the 'deployments' folder. -->
     <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
     <id>openshift</id>
     <build>
        <finalName>testing</finalName>
        <plugins>
          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <outputDirectory>deployments</outputDirectory>
                      <warName>ROOT</warName>
                </configuration>
            </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

谢谢您的帮助!

使用Fiala

我认为您在打开websocket时尝试连接到不存在的端点。

这(请注意,您错过了/../):

var wsUri = "ws://" + document.location.hostname + ":8000" + document.location.pathname + "/../serverendpoint";

...将适用于您部署到WildFly的文件,如下所示:

├── pom.xml
└── src
    └── main
        ├── java
        │   └── testing
        │       └── serverendpoint.java
        └── webapp
            ├── MyTest.html
            └── WEB-INF
                └── web.xml

我已经在OpenShift Online上的WildFly 10磁带上使用您的代码(带有修改的端点路径)检查了此内容。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我想把数组 [1,2,3,4,5,6,7,8,9,10,11] 变成数组 [1,2,3,4,5,6,7,8,9,1 ,0,1,1] 仅使用此算法

来自分类Dev

为什么3-1 * 8 + 2 * 3等于1

来自分类Dev

在Angular 8中使用Redux在1个效果中返回2个动作

来自分类Dev

JSON文件处理错误:使用UTF-8编码的文件时,JSONArray文本必须以'['开头1 [字符2行1]

来自分类Dev

JSON文件处理错误:使用UTF-8编码的文件时,JSONArray文本必须以'['开头1 [字符2行1]

来自分类Dev

如何使用类ClientWebSocket通过Windows Phone 8上的Web套接字发送/接收消息?

来自分类Dev

2分钟后,Python套接字客户端断开连接

来自分类Dev

逐步添加DIV ... 1、2、3、4、8、16

来自分类Dev

逐步添加DIV ... 1、2、3、4、8、16

来自分类Dev

RailsTutorial第8章错误的参数数量(1对2)

来自分类Dev

拆分整数 8 --> [1,7],[2,6]

来自分类Dev

Windows8上的Boot2Docker无法启动,原因是“未找到eth1的IP”

来自分类Dev

由于“找不到eth1的IP”,Windows8上的Boot2Docker无法启动

来自分类Dev

我如何循环几何序列。我需要在 1、2、4、8、16 上循环一些函数

来自分类Dev

当接口1上有:: 1时,为什么可以将此套接字绑定到:: 1%2?

来自分类Dev

当接口1上有:: 1时,为什么可以将此套接字绑定到:: 1%2?

来自分类Dev

使用Java 8方法获取HashMap <T1,Set <T2 >>的最小键和整数

来自分类Dev

使用Python套接字连接AWS EC2实例

来自分类Dev

如何在iOS8中使用coreplot在x1,y,1,y2之间绘制多条线?

来自分类Dev

在不使用for循环的情况下,将2 * 2像素图像重新排列为单个8 x 8矩阵,每个图像由1 x 4 numpy向量给定

来自分类Dev

在不使用for循环的情况下,将2 * 2像素的图像重新排列为单个的8 x 8矩阵,每个图像由1 x 4 numpy向量给定

来自分类Dev

'utf8'编解码器无法解码字节0xbd CSV文件1/2字符

来自分类Dev

在Windows 8上拒绝使用SSH连接到Amazon EC2的权限

来自分类Dev

iOS8上的Mailcore2

来自分类Dev

如何使用WiFi Direct连接2台Windows 8机器?

来自分类Dev

如何重复序列:r中的1,2,3,4,5,6,1,2,3,4,5,6,7,8,9,10,7,8,9,10

来自分类Dev

数据库值为 ["", "5", "1", "2", "8", "6", "9"] 在 Rails Console 中显示为 "[\"\", \"5\", \"1\"、\"2\"、\"8\"、\"6\"、\"9\"]"?

来自分类Dev

Win8计算机1可以看到但无法访问家庭wifi网络上的计算机2

来自分类Dev

根据地图 2 中的过滤条件过滤地图 1 的键,并使用 java8 流过滤地图 3 中每个项目的信息

Related 相关文章

  1. 1

    我想把数组 [1,2,3,4,5,6,7,8,9,10,11] 变成数组 [1,2,3,4,5,6,7,8,9,1 ,0,1,1] 仅使用此算法

  2. 2

    为什么3-1 * 8 + 2 * 3等于1

  3. 3

    在Angular 8中使用Redux在1个效果中返回2个动作

  4. 4

    JSON文件处理错误:使用UTF-8编码的文件时,JSONArray文本必须以'['开头1 [字符2行1]

  5. 5

    JSON文件处理错误:使用UTF-8编码的文件时,JSONArray文本必须以'['开头1 [字符2行1]

  6. 6

    如何使用类ClientWebSocket通过Windows Phone 8上的Web套接字发送/接收消息?

  7. 7

    2分钟后,Python套接字客户端断开连接

  8. 8

    逐步添加DIV ... 1、2、3、4、8、16

  9. 9

    逐步添加DIV ... 1、2、3、4、8、16

  10. 10

    RailsTutorial第8章错误的参数数量(1对2)

  11. 11

    拆分整数 8 --> [1,7],[2,6]

  12. 12

    Windows8上的Boot2Docker无法启动,原因是“未找到eth1的IP”

  13. 13

    由于“找不到eth1的IP”,Windows8上的Boot2Docker无法启动

  14. 14

    我如何循环几何序列。我需要在 1、2、4、8、16 上循环一些函数

  15. 15

    当接口1上有:: 1时,为什么可以将此套接字绑定到:: 1%2?

  16. 16

    当接口1上有:: 1时,为什么可以将此套接字绑定到:: 1%2?

  17. 17

    使用Java 8方法获取HashMap <T1,Set <T2 >>的最小键和整数

  18. 18

    使用Python套接字连接AWS EC2实例

  19. 19

    如何在iOS8中使用coreplot在x1,y,1,y2之间绘制多条线?

  20. 20

    在不使用for循环的情况下,将2 * 2像素图像重新排列为单个8 x 8矩阵,每个图像由1 x 4 numpy向量给定

  21. 21

    在不使用for循环的情况下,将2 * 2像素的图像重新排列为单个的8 x 8矩阵,每个图像由1 x 4 numpy向量给定

  22. 22

    'utf8'编解码器无法解码字节0xbd CSV文件1/2字符

  23. 23

    在Windows 8上拒绝使用SSH连接到Amazon EC2的权限

  24. 24

    iOS8上的Mailcore2

  25. 25

    如何使用WiFi Direct连接2台Windows 8机器?

  26. 26

    如何重复序列:r中的1,2,3,4,5,6,1,2,3,4,5,6,7,8,9,10,7,8,9,10

  27. 27

    数据库值为 ["", "5", "1", "2", "8", "6", "9"] 在 Rails Console 中显示为 "[\"\", \"5\", \"1\"、\"2\"、\"8\"、\"6\"、\"9\"]"?

  28. 28

    Win8计算机1可以看到但无法访问家庭wifi网络上的计算机2

  29. 29

    根据地图 2 中的过滤条件过滤地图 1 的键,并使用 java8 流过滤地图 3 中每个项目的信息

热门标签

归档