cindy源码阅读(1) hello word

[size=large]Cindy是一个强壮,可扩展,高效的异步I/O框架。支持TCP,SSL-TCP, UDP和Pipe。和他类似的有mina。

先看一个cindy的hello word,这个是我在官方的例子上做了修改,这个是最简单的了。
可以看到cindy的基本操作就是打开一个session,可以简单理解为就是一个socket,然后向这个 session发送消息。[/size]
session.send("hello, world!");
,[size=large]session收到消息之后会执行SessionHandler的objectReceived。objectReceived就可以根据自己的需求自己去写了。[/size]
package net.sf.cindy.example.helloworld;

import net.sf.cindy.Session;
import net.sf.cindy.SessionHandlerAdapter;
import net.sf.cindy.decoder.SerialDecoder;
import net.sf.cindy.encoder.SerialEncoder;
import net.sf.cindy.session.nio.PipeSession;

public class HelloWorld {

public static void main(String[] args) throws Exception {
Session session = new PipeSession();
session.setPacketEncoder(new SerialEncoder());
session.setPacketDecoder(new SerialDecoder());
session.setSessionHandler(new SessionHandlerAdapter() {
public void objectReceived(Session session, Object obj)throws Exception {
System.out.println("received: " + obj);
}
});
session.start().complete();

session.send("hello, world!");
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值