Mam kod dla klienta wręcz wzięty ze strony Oracla
package com.dataSender;
import android.app.Activity;
import java.net.*;
import java.io.*;
import android.app.AlertDialog;
import android.os.Bundle;
public class DataSenderActivity extends Activity {
/** Called when the activity is first created. */
public String getPage() throws Exception
{
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
echoSocket = new Socket("192.168.1.2", 7); //numer IP mojego serwera w podsieci
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
echoSocket.getInputStream()));
} catch (UnknownHostException e) {
return "Don't know about host: localhost.";
} catch (IOException e) {
return "Couldn't get I/O for the connection to: localhost."; //!!!!!!!!!!!!!ten oto wyjątek się aktywuje, choć nie powinien
}
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;
//while ((userInput = stdIn.readLine()) != null) {
out.println("test");
userInput=in.readLine();
//System.out.println("echo: " + in.readLine());
//}
out.close();
in.close();
stdIn.close();
echoSocket.close();
return userInput;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Packing List");
try{
alertDialog.setMessage(getPage());
}
catch(Exception e)
{
alertDialog.setMessage("unable to connect");
}
alertDialog.show();
}
}
[/code]
no i cały bajer polega na tym, że jeśli zawartość funkcji getPage odpalam na normalnym komputerze, to wszystko śmiga, zaś kiedy wsadzam to do kodu przystosowanego dla androida, to wyrzuca mi wyjątek “Couldn’t get I/O for the connection to: localhost”. Na stronie androida dla developerów jest ładnie napisane, że te standardowe metody do przesyłu danych powinny spokojnie działać… czy jest coś jeszcze o czym powinienem wiedzieć? czy może istnieje jakieś powiadomienie, że w tym programie będę korzystał z internetu, a czego nie napisałem? na czym może polegać problem?