編輯:Android開發教程
一個簡單的例子,對Mina框架有了大體的了解,在上節的基礎上,看看 怎樣實現客戶端與服務端的通信,
廢話不多說了,直接看代碼:
public class Test {
public static void main(String[] args) throws Exception{
SocketConnector connector = new NioSocketConnector();
IoFilter filter = new ProtocolCodecFilter(new TextLineCodecFactory());
connector.getFilterChain().addLast("vestigge", filter);
SocketAddress soketAddress = new InetSocketAddress("127.0.0.1", 5469);
connector.setHandler(new ClientHandler());
ConnectFuture future= connector.connect(soketAddress);
future.join();
if (!future.isConnected()) {
System.out.println("連接服務器失敗");
return;
}
future.getSession().write("hello");
}
}
可以看到代碼與服務器端的代碼很像,也是非常的簡單,這就是框架的好處,不用再重復發明輪子,省了不少事,
public class ClientHandler extends IoHandlerAdapter {
public void messageReceived(IoSession arg0, Object message) throws Exception {
System.out.println("收到服務器消息:" + message.toString());
}
public void exceptionCaught(IoSession arg0, Throwable arg1)
throws Exception {
}
}
效果演示:

如何讓你的iphone,ipad,android正常使用Lync 2013
一、生產環境1.經驗:1) 保證A.你的PC在intranet和internet上正常使得Lync 2013B.你的iphone,ipad,andro
Android簡明開發教程二十三:發布應用
到這裡基本介紹了Android開發的一些基本知識,在開發實際應用時最常用的幾個參考是:The Developer’s GuideAndroid Referen
在Android應用中使用百度地圖api
本篇通過一個簡單的示例一步步介紹如何在Android應用中使用百度地圖api。1)下載百度地圖移動版 API(Android)開發包要在Android應用中使用百度地圖A
android SQLite數據庫用法圖文詳解(附源碼)
1.背景SQLite是嵌入式設備使用的一種輕量型數據庫。可以通過執行sql語句對數據庫進行操作,android也為其提供了完善的函數接口支持。下面就來實現一個簡單的數據庫