nbsp; //22 return pipeline;23 }24 }ServerMain 1 public static main(String[] args) 2 { 3 // 开始NIO线程 4 ChannelFactory factory = new NioServerSocketChannelFactory(Executors 5 .newCachedThreadPool(), Executors.newCachedThreadPool()); 6 // 服务启始点 7 ServerBootstrap bootstrap = new ServerBootstrap(factory); 8 // 处理过滤器 9 bootstrap.setPipelineFactory(new PushServerPipelineFactory());10 // 设置相关参数11 bootstrap.setOption("child.tcpNoDelay", true);12 // 设置相关参数13 bootstrap.setOption("child.keepAlive", true);14 // 绑定相关端口15 bootstrap.bind(new InetSocketAddress(getPushPort()));16 } Flex客户端 FlexSocket 1 public class FlexSocket 2 { 3 4 //发送包 5 public function send(type:int, obj:PushMessage):Boolean 6 { 7 if (_socket == null) 8 { 9 return false;10 }11 //手动限制不给发送的时候用12 if (socketState == socket_state_closed || socketState == socket_state_connecting)13 {14 return false;15 }16 if (!_socket.connected)17 {18 return false;19 }20 var byteArr:ByteArray=objToByteaArray(obj);21 var msgHead:MsgHead=new MsgHead(type, byteArr.length);22 sendMsg(msgHead.getType(), msgHead.getSize(), byteArr);23 return true;24 }25 26 //接受包27 private function getDataHandler(e:ProgressEvent):void28 {29 _timeServerDead.stop();30 _timeServerDead.reset();31 if (_socket.bytesAvailable >= 8 && !_isReadHead)32 {33 _recvPackageType=_socket.readIn