該應用程序的目的是簡單地將字符串對象發送到我的機器上的服務器。所有端口轉發配置都是在我使用機器上的java客戶端測試服務器時設置的。Android和對象輸出流:對峙
問題在於從android客戶端與服務器交談。服務器似乎從來沒有被擊中。
該應用程序的基本流程:簡單屏幕1按鈕& 1 textview。按鈕發送對象到服務器,服務器響應消息,更新文本視圖。正如我所說的那樣,服務器似乎從未被擊中。任何人有任何想法我可以做什麼來解決這個問題?
public class ObjectTestActivity extends Activity {
Button submit;
private String string = "Hello Android";
private ObjectOutputStream oos;
private ObjectInputStream ois;
private final int PORT = 3000;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button send = (Button) findViewById(R.id.send);
tv = (TextView) findViewById(R.id.tv);
try{
InetAddress host = InetAddress.getLocalHost();
Socket socket = new Socket("xx.xx.xxx.xxx", PORT);
oos = new ObjectOutputStream(socket.getOutputStream());
ois = new ObjectInputStream(socket.getInputStream());
}catch(UnknownHostException e){}
catch(IOException e){}
}
public void onClick(View view){
try{
oos.writeObject(string);
String serverMsg = (String) ois.readObject();
ois.close();
oos.close();
tv.setText("Message from Server: " + serverMsg);
}catch(IOException e){}
catch(ClassNotFoundException e){}
}
}
你可以發佈你的Manifest文件的權限嗎? – hovanessyan 2012-02-22 16:55:00