Reputation: 64854
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 ?
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
Upvotes: 0
Views: 1204
Reputation: 20936
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;
}
}
Upvotes: 1