0

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

Adham
  • 63,550
  • 98
  • 229
  • 344

1 Answers1

1

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;
    }
}
Yury
  • 20,618
  • 7
  • 58
  • 86
  • I don't want to use a simple example, I want to work on a more complex project, where the efficiency and scalability are the most things I matter about – Adham Dec 26 '11 at 12:05