• 大小: 95KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-07
  • 语言: Java
  • 标签: Netty  SocketIo  webChat  

资源简介

客户端为SocketIO 服务器端为Java Netty WebChat聊天不错的选择

资源截图

代码片段和文件信息

package com.corundumstudio.socketio.demo;

import com.corundumstudio.socketio.AckCallback;
import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.VoidAckCallback;
import com.corundumstudio.socketio.listener.DataListener;

public class AckChatLauncher {

    public static void main(String[] args) throws InterruptedException {

        Configuration config = new Configuration();
        config.setHostname(“localhost“);
        config.setPort(9092);

        final SocketIOServer server = new SocketIOServer(config);
        server.addEventListener(“ackevent1“ Chatobject.class new DataListenerject>() {
            @Override
            public void onData(final SocketIOClient client Chatobject data final AckRequest ackRequest) {

                // check is ack requested by client
                // but it‘s not required check
                if (ackRequest.isAckRequested()) {
                    // send ack response with data to client
                    ackRequest.sendAckData(“client message was delivered to server!“ “yeah!“);
                }

                // send message back to client with ack callback WITH data
                Chatobject ackChatobjectData = new Chatobject(data.getUserName() “message with ack data“);
                client.sendEvent(“ackevent2“ new AckCallback(String.class) {
                    @Override
                    public void onSuccess(String result) {
                        System.out.println(“ack from client: “ + client.getSessionId() + “ data: “ + result);
                    }
                } ackChatobjectData);

                Chatobject ackChatobjectData1 = new Chatobject(data.getUserName() “message with void ack“);
                client.sendEvent(“ackevent3“ new VoidAckCallback() {

                    protected void onSuccess() {
                        System.out.println(“void ack from: “ + client.getSessionId());
                    }

                } ackChatobjectData1);
            }
        });

        server.start();

        Thread.sleep(Integer.MAX_VALUE);

        server.stop();
    }

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\
     文件          52  2015-02-19 06:47  netty-socketio-demo-master\.gitignore
     文件        1442  2015-02-19 06:47  netty-socketio-demo-master\README.md
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\client\
     文件        3355  2015-02-19 06:47  netty-socketio-demo-master\client\ack-index.html
     文件        2723  2015-02-19 06:47  netty-socketio-demo-master\client\binary-event-index.html
     文件       99896  2015-02-19 06:47  netty-socketio-demo-master\client\bootstrap.css
     文件        2196  2015-02-19 06:47  netty-socketio-demo-master\client\event-index.html
     文件        2865  2015-02-19 06:47  netty-socketio-demo-master\client\flashsocket-index.html
     文件        2767  2015-02-19 06:47  netty-socketio-demo-master\client\index.html
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\client\js\
     文件       94840  2015-02-19 06:47  netty-socketio-demo-master\client\js\jquery-1.7.2.min.js
     文件       10215  2015-02-19 06:47  netty-socketio-demo-master\client\js\moment.min.js
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\client\js\socket.io\
     文件       91999  2015-02-19 06:47  netty-socketio-demo-master\client\js\socket.io\socket.io.js
     文件        4326  2015-02-19 06:47  netty-socketio-demo-master\client\namespace-index.html
     文件        2164  2015-02-19 06:47  netty-socketio-demo-master\client\ssl-event-index.html
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\server\
     文件        2159  2015-02-19 06:47  netty-socketio-demo-master\server\pom.xml
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\server\src\
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\java\
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\java\com\
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\java\com\corundumstudio\
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\java\com\corundumstudio\socketio\
     目录           0  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\java\com\corundumstudio\socketio\demo\
     文件        2286  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\java\com\corundumstudio\socketio\demo\AckChatLauncher.java
     文件        1200  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\java\com\corundumstudio\socketio\demo\BinaryEventLauncher.java
     文件         893  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\java\com\corundumstudio\socketio\demo\ChatLauncher.java
     文件         610  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\java\com\corundumstudio\socketio\demo\Chatobject.java
     文件        1017  2015-02-19 06:47  netty-socketio-demo-master\server\src\main\java\com\corundumstudio\socketio\demo\EventChatLauncher.java
............此处省略4个文件信息

评论

共有 条评论