Apache MINA Java TCP 客户端-服务器通信

发布于 2024-10-07 09:27:33 字数 112 浏览 0 评论 0原文

我想使用 apache mina 来进行 TCP 客户端服务器通信。 谁能给出代码吗? 我在任何地方都找不到它...... google 没找到。 我想通过 mina 发送和接收短信。 所以请帮助我......

i want co communicate TCP client server communication using apache mina.
can anyone give the code ?
i cant find it in any were....
google is failed to find it.
i want to send and recieve text messages via mina .
so please help me....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤星 2024-10-14 09:27:33

很简单
在服务器端

 SocketConnectorConfig SOCKET_CONFIG = new SocketConnectorConfig();

        IoFilter charsetFilter = new ProtocolCodecFilter(
        new TextLineCodecFactory(Charset.forName("UTF-8")));
        SOCKET_CONFIG.getFilterChain().addLast("codec", charsetFilter);
theIoAcceptor.bind(new InetSocketAddress(thePort),
                      new TriggerReceiverHandler();

,ioAcceptor 的类型为 org.apache.mina.common.IoAcceptor 您可以使用 NioDatagramAcceptor 实例化它

TriggerReceiverHandler 是该类处理消息和会话相关事件。
它需要扩展IoHandlerAdapter

这是服务器用的。同样,对于客户端,唯一的变化是您使用 IoConnector 代替 IoAcceptor。

这是一个例子,也很好地解释了。
http://www.techbrainwave.com/?p=912

It is very simple
on the server side

 SocketConnectorConfig SOCKET_CONFIG = new SocketConnectorConfig();

        IoFilter charsetFilter = new ProtocolCodecFilter(
        new TextLineCodecFactory(Charset.forName("UTF-8")));
        SOCKET_CONFIG.getFilterChain().addLast("codec", charsetFilter);
theIoAcceptor.bind(new InetSocketAddress(thePort),
                      new TriggerReceiverHandler();

here ioAcceptor is of type org.apache.mina.common.IoAcceptor you can instantiate it by using NioDatagramAcceptor

TriggerReceiverHandler is the class that handles the messages and session related events.
it needs to extend the IoHandlerAdapter.

This is for server. Similarly for client the only change is instead of IoAcceptor you use the IoConnector.

Here is an example, well explained too.
http://www.techbrainwave.com/?p=912

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文