昨天遇到了一个很神奇的问题,因为有一个客户端的请求,我并没有在服务器端发送相应的请求码,但这个请求却执行了;开始一直以为是服务端的某个地方没有注意,找来找去发现,真是没有发送呀,就在客户端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源码
对于MIMO信道的统计模型的描述,介绍了信道相关矩阵的生成,以及信道矩阵的生成
Waveform-Design-and-Accurate-Channel-Estimation-for-Frequency-Ho
Laravel开发-the-laravel-fcm-channel Laravel FCM频道
Laravel开发-laravel-hooks-notification-channel 挂钩通知驱动程序
d0712003wp1-combined-los-nlos-uwb-channel-model.pdf
Laravel开发-laravel-mandrill-notification-channel Laravel 5.3的Mandrill通知频道
Laravel开发-laravel-stream-notification-channel Laravel 5.3的流通知通道
AVR136 - Low-jitter Multi-channel Software
Channel Codes Classical and Modern - 2009 William E.Ryan and Shu Lin
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
Channel coding techniques
% 题目6 BER for BPSK in Rayleigh channel % 任务要求: % 1.用MATLAB产生0、1的随机二进制序列,采用BPSK,0->1,1->-1; % 2.信道为瑞利信道(Rayleigh channel),需要用子函数(randn())生成瑞利分布函数(不能...
Laravel开发-laravel-notification-channel-turbosms Laravel 5.3 的Turbo短信通知频道。
channel estimation. channel estimation can be done by acquiring channel state information.
Laravel开发-laravel-notification-channel-voicecombg Laravel 5.3 的VoiceCom BG通知频道。
开始您的研究。然后,您可以使用正态分布为这些其他值生成数字
script_ber_mimo_zf_bpsk_rayleigh_channel_源码
FBMC-channel-estimation-based-on-SVR-master