Android クライアントが文字列をサーバーに送信します。サーバーはデバイスからの接続を正しいポートで認識しますが、それだけです.何が起こるかは、文字列がサーバーコンソールに出力されることです.
参考までに、Androidアプリ内で実行せずにまったく同じクライアントを作成しましたが、正常に動作するため、Android側で何かが欠けていると思います。この問題を解決するための提案を誰でも提供できますか。どうもありがとう。
クライアントコード:
public class ObjectTestActivity extends Activity {
Button submit;
TextView tv;
private String name = "Hello Android";
private DataOutputStream dos;
private DataInputStream dis;
private final int PORT = 3000;
Button send;
InetAddress host;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
send = (Button) findViewById(R.id.send);
tv = (TextView) findViewById(R.id.tv);
try{
host = InetAddress.getLocalHost();
Socket socket = new Socket("xx.xx.xxx.xxx", PORT);
dos = new DataOutputStream(socket.getOutputStream());
dis = new DataInputStream(socket.getInputStream());
}catch(UnknownHostException e){}
catch(IOException e){}
}
public void onClick(View view){
try{
dos.writeUTF(name);
dos.flush();
dis.close();
dos.close();
}catch(IOException e){}
}