Ui篇--layout_weight体验(实现按比例显示)
本次练习中是监听2个端口
applicationContext-mina.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//spring//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="Java.net.SocketAddress">
<bean
class="org.apache.mina.integration.spring.InetSocketAddressEditor" />
</entry>
</map>
</property>
</bean>
<!--创建服务器-->
<bean id="ioAcceptor"
class="org.apache.mina.integration.spring.IoAcceptorFactoryBean">
<property name="target">
<bean
class="org.apache.mina.transport.socket.nio.SocketAcceptor" />
</property>
<property name="bindings">
<list>//这里是个list 里面可以创建多个监听
<bean
class="org.apache.mina.integration.spring.Binding">
<property name="address" value=":8888" /> //监听端口:8888
<property name="handler" ref="SampleHandler" />// SampleHandler:定义服务器的handler
<property name="serviceConfig">
<bean
class="org.apache.mina.transport.socket.nio.SocketAcceptorConfig">
<property name="filterChainBuilder "//配置filter
ref="filterChainBuilder" /> //指向: filterChainBuilder
<property name="reuseAddress" value="true" />
</bean>
</property>
</bean>
<bean
class="org.apache.mina.integration.spring.Binding">
<property name="address" value=":9999" /> //第二个监听端口:9999
<property name="handler" ref="bossSampleHandler" /> //监听该端口的 handler
<property name="serviceConfig">
<bean
class="org.apache.mina.transport.socket.nio.SocketAcceptorConfig">
<property name="filterChainBuilder"
ref="filterChainBuilder" />
<property name="reuseAddress" value="true" />
</bean>
</property>
</bean>
</list>
</property>
</bean>
<bean id="SampleHandler" class="cn.org.handler.HandlerTwo" />
<bean id="bossSampleHandler" class="cn.org.handler.HandlerOne" />
//定义filter
<bean id="filterChainBuilder"
class="org.apache.mina.integration.spring.DefaultIoFilterChainBuilderFactoryBean">
<property name="filters">
<list>
<bean
class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg>
<bean
class="org.apache.mina.filter.codec.textline.TextLineCodecFactory" /> //这个是编码格式filter
</constructor-arg>
</bean>
<bean class="org.apache.mina.filter.LoggingFilter" / >//日志的filter
</list>
</property>
</bean>
</beans>
sprng的简单配置文件就是这样:
然后看 handler:
SampleHandler 和 bossSampleHandler 。我写的都是一样的:
package cn.org.handler;
import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
public class HandlerOne extends IoHandlerAdapter {
public HandlerOne() {
// TODO Auto-generated constructor stub
}
@Override
public void exceptionCaught(IoSession session, Throwable cause)
throws Exception {
}
@Override
public void messageReceived(IoSession session, Object message)
throws Exception {
// TODO Auto-generated method stub
System.out.println("收到信息");
System.out.println("message :"+message.toString());
}
@Override
public void messageSent(IoSession session, Object message) throws Exception {
System.out.println("小心发送");
}
@Override
public void sessionClosed(IoSession session) throws Exception {
// TODO Auto-generated method stub
super.sessionClosed(session);
}
@Override
public void sessionCreated(IoSession session) throws Exception {
System.out.println(session.getRemoteAddress().toString() +"---create");
}
@Override
public void sessionIdle(IoSession session, IdleStatus status)
throws Exception {
System.out.println(session.getServiceAddress() +"IDS");
}
@Override
public void sessionOpened(IoSession session) throws Exception {
System.out.println("连接打开:"+session.getLocalAddress());
}
}
现在测试:
Test.java
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
ClassPathXmlApplicationContext ct = new ClassPathXmlApplicationContext("applicationContext-mina.xml");
}
}
控制台打印出:
2010-1-16 19:00:51 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshingorg.springframework.context.support.ClassPathXmlApplicationContext@4b4333: display name [org.springframework.context.support.ClassPathXmlApplicationContext@4b4333]; startup date [Sat Jan 16 19:00:51 CST 2010]; root of context hierarchy
2010-1-16 19:00:51 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [applicationContext-mina.xml]
2010-1-16 19:00:51 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@4b4333]:org.springframework.beans.factory.support.DefaultListableBeanFactory@1975b59
2010-1-16 19:00:52 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons inorg.springframework.beans.factory.support.DefaultListableBeanFactory@1975b59: defining beans [org.springframework.beans.factory.config.CustomEditorConfigurer#0,ioAcceptor,SampleHandler,bossSampleHandler,filterChainBuilder]; root of factory hierarchy
表明服务器就已经启动了:
现在你可以用telent的方式测试。也可以写个客户端的测试类:
写了个客户端的测试类:Clint.java
public class Clint {
/**
* @param args
*/
final static char end = 0x1a;
public static void main(String[] args) {
SocketConnector connector = new SocketConnector();
SocketAddress address = new InetSocketAddress("127.0.0.1", 8888);
SocketConnectorConfig config = new SocketConnectorConfig();
config.setConnectTimeout(10);// 秒
connector.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "GB2312" )))); //设置编码过滤器
connector.getFilterChain().addLast( "logger", new org.apache.mina.filter.LoggingFilter() );
IoSession session =null;
ConnectFuture cf = connector.connect(address, new ClintHandler(),
config);
cf.join();
if (cf.isConnected()) {
session = cf.getSession();
System.out.println("连接成功");
session.write("abc");
}else{
System.out.println("连接失败!!!");
}
}
}
Ui篇--layout_weight体验(实现按比例显示)的更多相关文章
- layout_weight体验(实现按比例显示)
在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示.android并没用提 ...
- 转 layout_weight体验(实现按比例显示)
http://www.cnblogs.com/zhmore/archive/2011/11/04/2236514.html 在android开发中LinearLayout很常用,LinearLayou ...
- iOS开发UI篇—UIScrollView控件实现图片缩放功能
iOS开发UI篇—UIScrollView控件实现图片缩放功能 一.缩放 1.简单说明: 有些时候,我们可能要对某些内容进行手势缩放,如下图所示 UIScrollView不仅能滚动显示大量内容,还能对 ...
- iOS开发UI篇—UITableview控件基本使用
iOS开发UI篇—UITableview控件基本使用 一.一个简单的英雄展示程序 NJHero.h文件代码(字典转模型) #import <Foundation/Foundation.h> ...
- iOS开发UI篇—CAlayer(自定义layer)
iOS开发UI篇—CAlayer(自定义layer) 一.第一种方式 1.简单说明 以前想要在view中画东西,需要自定义view,创建一个类与之关联,让这个类继承自UIView,然后重写它的Draw ...
- iOS开发UI篇—CAlayer层的属性
iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...
- iOS开发UI篇—CAlayer(创建图层)
iOS开发UI篇—CAlayer(创建图层) 一.添加一个图层 添加图层的步骤: 1.创建layer 2.设置layer的属性(设置了颜色,bounds才能显示出来) 3.将layer添加到界面上(控 ...
- iOS开发UI篇—CALayer简介
iOS开发UI篇—CALayer简介 一.简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比如一个按钮.一个文本标签.一个文本输入框.一个图标等等,这些都是UIView. 其实 ...
- iOS开发UI篇—核心动画(UIView封装动画)
iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...
随机推荐
- C# 面向对象之概念理解
什么是对象? <韦氏大词典>中对对象定义: (1)某种可为人所感知的物质. (2)思维.感受或动作所作用的物质或精神体. ----说白了万物皆对象 熟悉的对象描述: 对象就是客观世界中的物 ...
- java基础知识回顾之---java String final类 容易混淆的java String常量池内存分析
/** * 栈(Stack) :存放基本类型的变量数据和对象的引用,但对象本身不存放在栈中,而是存放在堆(new 出来的对象)或者常量池中(字符串常量对象存放 在常量池中). 堆(heap):存 ...
- shop++ 安装
1.安装tomcat后 ,G:\apache-tomcat-6.0.35\conf\server.xml 中设置tomcat 编码为utf-8. 增加URIEncoding = "UTF-8 ...
- hdu 1536/1944 / POJ 2960 / ZOJ 3084 S-Nim 博弈论
简单的SG函数应用!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #inclu ...
- poj 3358 Period of an Infinite Binary Expansion
由乘2取整得到分数的小数位,可以找到规律!!! 例如:1/10,2/10,4/10,8/10,16/10,32/10,64/10…… 取整后:1/10,2/10,4/10,8/10,6/10,2/10 ...
- 关于DotNetBar中DataGridViewX 自动全屏 Anchor属性无效问题
由于在DataGridViewX 中使用了控件DataGridViewCheckBoxXColumn会导致 Anchor属性无效问题化,具体原因未知,建议改换为系统自带的DataGridViewChe ...
- C# 中的命名规则
需要注意: C# 区分大小写 ,若有int a 和 int A ,则a, 和 A是不同的 普通字段,属相,方法,类的命名规则: C#中推荐使用 camelCasing ,和 PascalCasing ...
- [Hibernate]dynamic-insert和dynamic-update属性
这二个属性默认情况均为false,你可以通过以下二种方式进行配置使用: 1.Annotation @Entity @Table(name = "stock_transaction" ...
- hdu2012
http://acm.hdu.edu.cn/showproblem.php?pid=2012 数组大小算错了.....郁闷-_- #include<iostream> #include&l ...
- MySQL 卸载 --Mac
pkill mysql sudo rm /usr/local/mysql sudo rm -rf /usr/local/mysql* sudo rm -rf /Library/StartupItems ...