0

My Adnroid app is running on AVD and Cassandra server is running on Windows 7 (same machine) Below is the code snippet I have used for connecting to Cassandra client.

TTransport tr = new TFramedTransport(new TSocket("127.0.0.1", 9160));
TProtocol proto = new TBinaryProtocol(tr);
Cassandra.Client client = new Cassandra.Client(proto);
tr.open();

I have tried to debug; it creates the socket with isClose() = 'false' (that means socket is open) but further it fails to connect (TSocket.open())

-------------------------Code from org.apache.thrift.transport.TSocket--------------------

try {
socket_.connect(new InetSocketAddress(host_, port_), timeout_);
inputStream_ = socket_.getInputStream();
outputStream_ = socket_.getOutputStream();
} catch (IOException iox) {
close();
throw new TTransportException(TTransportException.NOT_OPEN, iox);

}

It seems to be a problem with cross platform and the Windows OS (as Android apps are on Linux). Is there any better way I can connect to Cassandra server from Android app ? You help and time is higly appreciated.

Thanks Randeep

  • If you find this answer is correct then please accept as a correct answer, by mark right symbol below voting buttons on left hand side of my answr. (It will help you and other user also..) – user370305 Dec 14 '11 at 17:51

1 Answers1

4

I don't know what are you doing, (Its solved your problem or not) But one thing is getting clear that Android emulator doesn't understand localhost or 127.0.0.1, If you want to connect localhost then either use a public IP of system or 10.0.2.2 (for localhost)..

user370305
  • 108,599
  • 23
  • 164
  • 151
  • Hey! Thanks alot for the help. It worked for me. I have configured the Cassandra server with my public IP and used the same IP while connecting through Android app and everything works fine now. Thanks Randeep – user1097342 Dec 14 '11 at 13:54