Hi guys, I've some problems:
1)first I'm not able to read a file:(
2)second seems that my code that have to simulate a Client can't
connect to my server.
maybe I'm wrong something, Ip address(I think it is right)? I have set
the virtual device on port 5554 (the default)..I need to redirect the
host port?
this is my code:
;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import java.io.*;
import java.net.*;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class C extends Activity {
/** Called when the activity is first created. */
private PrintWriter savedpoint;
private Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try{
savedpoint = new PrintWriter(openFileOutput
("Data.dat",MODE_APPEND));
for(int i=0;i<20;i++)//scrive coordinate
{
savedpoint.println(-78.443221+"i"+" "+120.344423+"i");
}
F thread=new F(getFilesDir(),this);
thread.start();
}catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
//thread that have to acess to the server
class F extends Thread{
File directory;
Context context;
private final static String host = "10.0.2.2";
private final static int port = 2120;
F(File directory,Context context)
{this.directory=directory;this.context=context;}
public void run()
{
try{
Socket socket = null;
PrintWriter out = null;
InetAddress ip = InetAddress.getByName(host);
socket = new Socket(ip,port); ----->SEEMS THERE IS NO
CONNECTIONS, BECAUSE THE SERVER DOESN'T SIGN ANYTHING
out = new PrintWriter( new BufferedWriter( new
OutputStreamWriter
(socket.getOutputStream())),true);
Scanner s=new Scanner(directory+"Data.dat"); ---> The right
way?
try {
while (true) {
String l = s.nextLine(); ---->ERROR
out.println(l);
}
} catch (NoSuchElementException e) {s.close();
out.println("*");
}//catch(FileNotFoundException e){}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();}
}
}
the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="prova.client"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/
app_name">
<activity android:name=".C"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
thanks in advance for any help..
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---