問題!用Mina自帶的客戶端寫,數(shù)據(jù)發(fā)送不出去?
package?com.example.demo; import?java.io.BufferedReader; import?java.io.InputStreamReader; import?java.net.InetAddress; import?java.net.InetSocketAddress; import?org.apache.mina.core.future.ConnectFuture; import?org.apache.mina.core.session.IoSession; import?org.apache.mina.filter.codec.ProtocolCodecFilter; import?org.apache.mina.filter.codec.textline.TextLineCodecFactory; import?org.apache.mina.transport.socket.nio.NioDatagramConnector; public?class?MinaClientTest?{ public?static?void?main(String[]?args)?throws?Exception?{ //?TODO?Auto-generated?method?stub NioDatagramConnector?connector?=?new?NioDatagramConnector(); connector.setHandler(new?MyMinaClientHandler()); connector.getFilterChain().addLast("codec",?new?ProtocolCodecFilter(new?TextLineCodecFactory())); ConnectFuture?future?=?connector.connect(new?InetSocketAddress(InetAddress.getLocalHost(),?8989)); future.awaitUninterruptibly(); System.out.println("InetAddress.getLocalHost()?:"+InetAddress.getLocalHost()); IoSession?session?=?future.getSession(); // writeToServer(session); BufferedReader?bf??=?null; bf?=?new?BufferedReader(new?InputStreamReader(System.in)); String?line?=null; while(!(line=bf.readLine()).equals("bye")){ System.out.println(line); session.write(line); } bf.close(); } }
問題!用Mina自帶的客戶端寫,數(shù)據(jù)發(fā)送不出去?
2016-09-15
NioDatagramConnector 這個寫錯了。改成這個NioSocketConnector
2016-05-19
客戶端發(fā)送,服務(wù)器收不到?什么原因,求大神解決?我和老師寫的一模一樣的?