是否有适用于 Android 客户端的开源 TCP 服务器?

发布于 2024-12-23 07:25:14 字数 249 浏览 1 评论 0原文

我正在寻找一个开源 TCP 服务器,它可以在计算机上配置为 Android 客户端应用程序的服务器。由于我想在 Android 设备之间创建消息传递服务,

我找到了 Apache Mina 开源 TCP 服务器,它适用于 Android 操作系统吗?

编辑

抱歉,对于Mina,我不是指服务器,而是指总体框架。我可以使用 Apache Mina 为 android 创建 android java 客户端吗

I searching for an open source TCP server that can be configured on the computer to work as server for client applications for Android. As I want to create messaging services between Android devices,

I've found Apache Mina open source TCP server, does it work for android OS ?

edit

sorry, for Mina, I don't mean the server, I mean the general framework. Can I create android java client for android using Apache Mina

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

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

发布评论

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

评论(1

如此安好 2024-12-30 07:25:15

作为 TCP 服务器,我使用一个简单的 java 应用程序,它由 1 个类组成。这里是。希望这会对您有所帮助!

import java.net.*;
import java.io.*;

public class PortMonitor {
    private static int port = 8080;


    /**
     * JavaProgrammingForums.com
     */
    public static void main(String[] args) throws Exception {

        //Port to monitor
        final int myPort = port;
        ServerSocket ssock = new ServerSocket(myPort);
        System.out.println("port " + myPort + " opened");

        Socket sock = ssock.accept();
        System.out.println("Someone has made socket connection");

        OneConnection client = new OneConnection(sock);
        String s = client.getRequest();

    }

}

class OneConnection {
    Socket sock;
    BufferedReader in = null;
    DataOutputStream out = null;

    OneConnection(Socket sock) throws Exception {
        this.sock = sock;
        in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
        out = new DataOutputStream(sock.getOutputStream());
    }

    String getRequest() throws Exception {
        String s = null;
        while ((s = in.readLine()) != null) {
            System.out.println("got: " + s);
        }
        return s;
    }
}

As a tcp server I use a simple java application which consists of 1 class. Here it is. Hope this will help you!

import java.net.*;
import java.io.*;

public class PortMonitor {
    private static int port = 8080;


    /**
     * JavaProgrammingForums.com
     */
    public static void main(String[] args) throws Exception {

        //Port to monitor
        final int myPort = port;
        ServerSocket ssock = new ServerSocket(myPort);
        System.out.println("port " + myPort + " opened");

        Socket sock = ssock.accept();
        System.out.println("Someone has made socket connection");

        OneConnection client = new OneConnection(sock);
        String s = client.getRequest();

    }

}

class OneConnection {
    Socket sock;
    BufferedReader in = null;
    DataOutputStream out = null;

    OneConnection(Socket sock) throws Exception {
        this.sock = sock;
        in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
        out = new DataOutputStream(sock.getOutputStream());
    }

    String getRequest() throws Exception {
        String s = null;
        while ((s = in.readLine()) != null) {
            System.out.println("got: " + s);
        }
        return s;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文