`
AquariusM
  • 浏览: 145948 次
  • 性别: Icon_minigender_1
  • 来自: 南阳
社区版块
存档分类
最新评论

2010年8月11号---RedDwarf之Channel通信学习总结

阅读更多

    昨天遇到了一个很神奇的问题,因为有一个客户端的请求,我并没有在服务器端发送相应的请求码,但这个请求却执行了;开始一直以为是服务端的某个地方没有注意,找来找去发现,真是没有发送呀,就在客户端as程序中调试,后来发现这个case是放在紧靠着default的上边的。于是,就换了个位置发现确实不运行了,再考虑一下交互程序的特性,虽然在出问题的这个阶段客户端是处在一个timer()的delay事件中,但是这个时候客户端与服务器还是在通讯中,再具体点客户端的received()方法一直在运行过程中,所以每次都要执行一个default上边的那个case;
    但是再仔细看看才发现,都是因为没有写break的原因,并不是每一次都会执行default的,只有当case里确实没有给定的值时,才会执行default。
    又回到远点,一切都是基础基础很重要一定要扎实,不扎实就会在实践中出问题。
   
    游戏房间与player之间通过channel进行连接,这里进行解析:

  

    ChannelManager cm = AppContext.getChannelManager();

    DataManager dm = AppContext.getDataManager();

    //这里一般是新建一个用户自定义类型的ChannelListener,注意自定义类型ChannelListener必须实现 

    //ChannelListener和Serializable类

    ChannelListener listener1 = new userChannelListener();

    Channel channel1 = cm.createChannel("channelName",listener1,Delivery.RELIABLE);

   

    Room rm = new Room(channel1);

    dm.setBinding("room1",rm);

   

    这样就完成了一个基本的房间创建,Room为自定义类型,每一个Room对象都包含一个Channel对象和一个用户列表,用户列表可以用Collection 容器中的类型定义,根据自己的需求来设定;

    服务端:

    通过Channel.join()方法,将用户添加入Channel中,然后在服务器端,

    实现了ChannelListener的类,需要定义receiveMessage(Channel channel,ClientSession,ByteBuffer message)方法,这样服务器端Channel、客户端ClientSession还有客户端发送到服务器的数据ByteBuffer就可以实现客户端给服务端发送数据了。

     再来看客户端:

     客户端中在SimpleClientListener接口中,会有一个需要实现的方法

     joinedChannel(channel:ClientChannel):ClientChannelListener()

     该方法接受一个ClientChannel类型的对象作为参数。客户端需要保存这个参数,因为需要用这个参数的client()方法,发送数据给服务端;同时该方法的返回值是实现了ClientChannelListener 接口的对象。这个借口提供两个方法,一个receivedMessage和leftChannel方法。receivedMessage方法在服务端Channel发送一个数据包到客户端时调用,来接受服务端channel的消息。leftChannel()顾名思义,就是当客户离开channel时在客户端调用。

     基本上的流程在文档里都有,英文:

     As mentioned above, adding and removing users from the channel is under the control of the server application.How then does a client know what channels it is a part of and how to communicate on them? The answer is another callback on the SimpleClientListener interface: joinedChannel. The joinedChannel callback receives a ClientChannel object as its one parameter. The client application should save this object, since this is its interface for sending messages on the channel.
     The SimpleClient expects this callback to return an object that implements the ClientChannelListener interface. This interface has two methods on it, receivedMessage and leftChannel. The first is called on a callback whenever a packet for this user is received from the channel. The second callback is called if the server  removes this user from the channel.

 

    

分享到:
评论

相关推荐

    Indoor-Mapping-Using-the-VLC-Channel-State-Information-master源码

    标题 "Indoor-Mapping-Using-the-VLC-Channel-State-Information-master源码" 提供的信息表明,这是一个关于室内定位技术的项目,它利用了Visible Light Communication (VLC)的信道状态信息。VLC是一种利用可见光...

    BER-of-Nakagami-fading-channel-master_余使用寿命_

    标题中的“BER-of-Nakagami-fading-channel-master”指的是误码率(Bit Error Rate, BER)在Nakagami-m衰落信道中的研究。误码率是衡量通信系统性能的重要指标,它描述了在传输过程中数据错误的概率。Nakagami-m分布...

    BER-and-COM-Way-of-Channel-Compliance-Evaluation.pdf

    BER-and-COM-Way-of-Channel-Compliance-Evaluation-white-paper-sm-20160121

    script-ber-mimo-zf-bpsk-rayleigh-channel-源码

    标题中的"script-ber-mimo-zf-bpsk-rayleigh-channel"揭示了这段代码的核心内容,涉及到了几个关键的IT知识点。首先,我们来逐一解析这些术语: 1. **MIMO**(Multiple-Input Multiple-Output):MIMO是无线通信...

    Waveform-Design-and-Accurate-Channel-Estimation-for-Frequency-Ho

    Waveform Design and Accurate Channel Estimation for Frequency-Hopping MIMO Radar-Based Communications ...8. DFRC(Dual-Function Radar Communication):一种结合雷达和通信的技术,用于实现双功能雷达通信。

    Fibre Channel –Physical Interface-7 (FC-PI-7)Rev 0.04 -2017

    《Fibre Channel –Physical Interface-7 (FC-PI-7)Rev 0.04 -2017》是美国国家标准协会(American National Standards Institute,ANSI)发布的一份关于光纤通道物理接口的重要标准,主要关注64G FC(64吉比特光纤...

    QPSK-AWGN-channel.rar_BPSK AWGN channel_BPSK_QPSK_QPSK_QPSK cha

    标题中的“QPSK-AWGN-channel.rar_BPSK AWGN channel_BPSK_QPSK_QPSK cha”指的是一个关于QPSK调制在AWGN(Additive White Gaussian Noise,加性高斯白噪声)信道下的研究,同时包含了BPSK(Binary Phase Shift ...

    ieee802-15-4a-channel-model_SV_channel_model_sv_SV模型_

    标题中的“ieee802-15-4a-channel-model”指的是IEEE 802.15.4a无线通信标准中的信道模型。这个标准主要用于超低功耗、短距离无线通信,如Zigbee、WirelessHART等网络。在802.15.4a中,定义了多种信道模型来模拟实际...

    Laravel开发-laravel-stream-notification-channel

    在本文中,我们将深入探讨Laravel框架中的一个特定组件——`laravel-stream-notification-channel`,这是针对Laravel 5.3版本的一个扩展,用于实现流式通知功能。Laravel作为一个强大的PHP Web应用框架,提供了丰富...

    GSM-CHANNEL-CODING.rar_LPC_channel matlab_coding_convolutional c

    标题中的"GSM-CHANNEL-CODING.rar_LPC_channel matlab_coding_convolutional c"表明了这个压缩包内容主要涉及GSM(全球系统移动通信)信道编码,具体是使用MATLAB进行线性预测编码(LPC)信道的卷积编码实现。...

    [eBook]-Channel-Codes-Classical-and-Modern---2009_Channel Codes

    Channel Codes Classical and Modern - 2009 William E.Ryan and Shu Lin

    Laravel开发-laravel-notification-channel-turbosms

    在本文中,我们将深入探讨如何在 Laravel 开发中利用 `laravel-notification-channel-turbosms` 这一扩展包来实现 Turbo 短信服务。Laravel 是一个流行且强大的 PHP 框架,它提供了丰富的功能来简化 Web 应用程序的...

    IMT-Advanced.rar_IMT_IMT-A_IMT-A_channel_model_imt-advanced_imt平

    IMT(International Mobile Telecommunications)是国际电信联盟(ITU)为全球移动通信系统设定的一系列标准,用于定义未来的移动通信技术。"IMT-Advanced"是4G移动通信技术的一个重要阶段,它代表了第四代移动通信...

    JavaSocket学习---NIO实现非阻塞的通信

    总结来说,Java NIO为Socket通信提供了一种非阻塞的解决方案,通过`Selector`和`Channel`的组合,可以在单线程中处理多个连接,极大地提高了服务器的并发性能。`EchoServerNoBlock.java`、`EchoClient.java`和`...

    LTC2439 6-Bit 8-/16-Channel

    1、16-Channel Single-Ended or 8-Channel Differential Inputs 2、Low Supply Current (200µA, 4µA in Autosleep) 3、Rail-to-Rail Differential Input/Reference 4、16-Bit No Missing Codes 5、1µV RMS Noise,...

    ITU-R_IMT-A_channel_model

    ITU-R_IMT-A_channel_model

    (FC-PI-7) Fibre Channel –Physical Interface-7 (FC-PI-7)Rev 0.04

    此标准的发布日期为2017年,版本号为0.04,由美国国家标准学会(American National Standards Institute, ANSI)发布,是信息技术领域的美国国家标准。 FC-PI-7标准涵盖了64GFC(64吉比特Fibre Channel),而32GFC...

    BER-for-BPSK-in-Rayleigh-channel.m

    % 题目6 BER for BPSK in Rayleigh channel % 任务要求: % 1.用MATLAB产生0、1的随机二进制序列,采用BPSK,0->1,1->-1; % 2.信道为瑞利信道(Rayleigh channel),需要用子函数(randn())生成瑞利分布函数(不能...

    Laravel开发-laravel-notification-channel-voicecombg

    在本文中,我们将深入探讨如何在 Laravel 开发中利用 `laravel-notification-channel-voicecombg` 扩展包实现 VoiceCom BG 通知频道。Laravel 是一个流行的 PHP 框架,它为开发者提供了优雅的方式来构建 web 应用...

Global site tag (gtag.js) - Google Analytics