0

我的 Adnroid 应用程序在 AVD 上运行,而 Cassandra 服务器在 Windows 7(同一台机器)上运行 下面是我用于连接到 Cassandra 客户端的代码片段。

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();

我试过调试;它使用 isClose() = 'false' 创建套接字(这意味着套接字已打开),但进一步无法连接(TSocket.open())

--------------来自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);

}

这似乎是跨平台和 Windows 操作系统的问题(因为 Android 应用程序在 Linux 上)。有没有更好的方法可以从 Android 应用程序连接到 Cassandra 服务器?非常感谢您的帮助和时间。

谢谢兰迪普

4

1 回答 1

4

我不知道你在做什么,(它是否解决了你的问题)但是有一点很清楚,Android 模拟器不理解localhost或者127.0.0.1,如果你想连接本地主机,那么要么使用public IP系统或10.0.2.2(对于本地主机) ..

于 2011-12-14T11:00:13.497 回答