0

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

我找到了 Apache Mina 开源 TCP 服务器,它适用于 android OS 吗?

编辑

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

4

1 回答 1

1

作为 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;
    }
}
于 2011-12-25T19:00:01.590 回答