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

时间:2011-12-25 17:55:06

标签: android tcp messaging tcpclient apache-mina

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

我发现Apache Mina开源TCP服务器,它是否适用于Android操作系统?

修改

抱歉,对于Mina,我不是指服务器,我的意思是一般框架。我可以使用Apache Mina

为Android创建android java客户端

1 个答案:

答案 0 :(得分: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;
    }
}