私は変更された例に従っています。私は私のPC(Qtを使って)で書いたプログラムとコミュニケーションするためにオンラインで見つけました。データが受信されると、Qt関数は本当にシンプルですAndroidネットワーク接続。データを書き込むことはできますが、データを読み取ることはできません。 Qtサーバの使用
void FileTransferServer::on_dataReady(){
QByteArray buffer = socket->readAll();
ui->teLog->append("Received: " + QString(buffer));
QByteArray data;
QString msg = "Soy Qt!!";
data = msg.toLatin1();
qint32 value = socket->write(data);
ui->teLog->append("Sending reply of " + QString::number(value) + " bytes");
}
In android私はTCPクライアント用にAsyncTaskを実装しました。クライアントの主な機能のためのコードは以下の通りです:
public void run(){
try {
//here you must put your computer's IP address.
InetAddress serverAddr = InetAddress.getByName(SERVER_ADDRESS);
System.err.println("Attempting connection...");
//create a socket to make the connection with the server
Socket socket = new Socket(serverAddr, SERVER_PORT);
try {
//send the message to the server
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
System.err.println("Connection successful attempting to send message");
//To receive messages
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
int i = 0;
while (i < 10) {
i++;
out.println("This is Android!!");
// Waiting for response.
boolean msgRead = false;
String msg;
while (!msgRead) {
System.err.println("Attempting to read a message");
msg = in.readLine();
System.err.println("Message received: " + msg);
if (msg != null) {
//output.append("Reply: " + msg);
System.err.println("Reply: " + msg);
msgRead = true;
}
}
}
System.err.println("All done!");
} catch (Exception e) {
System.err.println("Error on sending message: " + e.getMessage());
} finally {
//the socket must be closed. It is not possible to reconnect to this socket
// after it is closed, which means a new socket instance has to be created.
socket.close();
}
} catch (Exception e) {
System.err.println("Error on connection: " + e.getMessage() + " And also " + e.toString());
}
私の問題は、私は自分の携帯電話にPCからのデータを送ることができるにもかかわらず、それは他の方法で回避動作しないということです。 (自分の携帯電話用)ここで
私のコンソール出力
09-06 20:54:32.619 31231-31245/? W/System.err: Attempting connection...
09-06 20:54:32.629 31231-31245/? W/System.err: Connection successful attempting to send message
09-06 20:54:32.629 31231-31245/? W/System.err: Attempting to read a message
私の簡単なのQtアプリケーションの出力がある間:示すようにプログラムは、メッセージを読み取ろうとする時にハングしかし
Accepted connection from ::ffff:192.168.1.107. Local address is ::ffff:192.168.1.110
Received: This is Android!!
Sending reply of 8 bytes
上記。私はQtのプログラムを終了したときに
はまた、私はこれらの
09-06 20:56:39.569 31231-31245/cmp.cmpreceiver W/System.err: Attempting to read a message
09-06 20:56:39.569 31231-31245/cmp.cmpreceiver W/System.err: Message received: null
のトンを取得する任意の一つは、私が間違ってやっているものを私に伝えることができますか?