クライアント -> サーバー -> クライアント通信 (一方向トラフィック) を含むアプリを作成しています。クライアントAからサーバーにデータを送信しました。テストは簡単で、コンソールに出力するだけですが、データが次のクライアントに送信されたかどうかをテストしようとしています。テキストビューを試してみましたが、このビューには何も表示されていませんが、データが到着していないためなのか、コーディングが間違っているためなのかわかりません。私はアンドロイドの経験があまりありません。
以下にコードを添付しました。誰かが助けてくれれば、本当に感謝しています。
よろしく、ゲイリー
public class Parent extends Activity {
private Socket s;
private PrintWriter p;
String location;
double Platitude, Plongitude;
double Clatitude, Clongitude;
double distance;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.parent);
Thread rec = new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
try {
s = new Socket("192.168.1.2", 1980);
InputStream fromServer = s.getInputStream();
while (s.isConnected()) {
Scanner r = new Scanner(fromServer);
if(r.hasNextLine())
{
location = r.nextLine();
}
TextView myTextview = (TextView) findViewById(R.id.dist);
myTextview.setText(location);
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
rec.start();
}