Can not connect lo localhot from emulator using socket

by Oskeol » Fri, 09 May 2008 16:01:35 GMT


Sponsored Links
 Hi,
I want to access an Eccho server in localhost.

Here is the Echo server in localhost




import java.net.*;
import java.io.*;
import java.util.Scanner;


public class EchoServer
{
        public static void main(String[] args)
        {
                try
                {
                        ServerSocket s = new ServerSocket(8189);
                        Socket incoming = s.accept();

                        try
                        {
                                InputStream inStream   = 
incoming.getInputStream();
                                OutputStream outStream = 
incoming.getOutputStream();
                                Scanner in = new Scanner(inStream);
                                PrintWriter out = new PrintWriter(outStream, 
true);
                                out.println("Hello! Enter BYE to exit");

                                boolean done = false;

                                while(!done && in.hasNextLine())
                                {
                                        String line = in.nextLine();
                                        out.println("Echo: "+ line);
                                        if(line.trim().equalsIgnoreCase("BYE"))
                                                done = true;
                                }

                        }
                        finally
                        {
                                incoming.close();
                        }

                }
                catch(IOException e)
                {
                        e.printStackTrace();
                }

    }
}


I have a client, on the emulatot that tries to connect to this server.
I use 10.0.2.2 to connect to localhost, but it doesn't work.

Socket s = new Socket("10.0.2.2", 8189);

Can anybody explain why this happen,

oskeol
--~--~---------~--~----~------------~-------~--~----~



Can not connect lo localhot from emulator using socket

by kobica » Mon, 12 May 2008 17:15:56 GMT


 >

have you tried to forward/redirect ports?
Maybe that is what you are missing.

Plus, take a look at:


Sponsored Links


Can not connect lo localhot from emulator using socket

by Oskeol » Tue, 13 May 2008 20:31:26 GMT


 Thanks, very much for your help.
Forwarding ports it does now work.

Thnx agani Kobi,

Oskeol
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Create a wav file and stock this into a data storage with Content Providers

How can I take:  "Create a wav file and stock this into a data storage
with Content Providers"

I try to use the same thing like the following exemple:

http://developer.android.com/intl/fr/guide/topics/providers/content-providers.html

with a Bitmap:

import android.provider.MediaStore.Images.Media;
import android.content.ContentValues;
import java.io.OutputStream;

// Save the name and description of an image in a ContentValues map.
ContentValues values = new ContentValues(3);
values.put(Media.DISPLAY_NAME, "road_trip_1");
values.put(Media.DESCRIPTION, "Day 1, trip to Los Angeles");
values.put(Media.MIME_TYPE, "image/jpeg");

// Add a new record without the bitmap, but with the values just set.
// insert() returns the URI of the new record.
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
values);

// Now get a handle to the file for that record, and save the data
into it.
// Here, sourceBitmap is a Bitmap object representing the file to save
to the database.
try {
    OutputStream outStream = getContentResolver().openOutputStream
(uri);
    sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
    outStream.close();
} catch (Exception e) {
    Log.e(TAG, "exception while writing image", e);


So I think is too similar but I'm really lose !!

Firstly I don't find how to create my File with my byte[].

I try to make that:

    byte[] decoded = Base64.decode( tabMsg[0].getMsgBase64() );

            ContentValues values = new ContentValues();
            values.put(Media.DISPLAY_NAME, "Voicemail1");
            values.put(Media.MIME_TYPE, "Audio/wav");

            Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
values);

            File m_wav = new File(uri.getEncodedPath(), "voicemail1.wav");

            try
            {
                OutputStream outStream = getContentResolver().openOutputStream
(uri);
                outStream.write(decoded);
                outStream.close();
            }
            catch (Exception e)
            {
                Log.e(TAG, "Exception while writing audio", e);
            }


Could you light me, please ??
What are you thinking about my little code and how can I
continuous ???

It's very hard to use the better arguments or parametres with:
values.put(...) and with : getContentResolver().insert(..)

Maybe I have to create my own Content Providers but I think is too
compicated !

Dany
--~--~---------~--~----~------------~-------~--~----~

2. unable to download youtube video's in android

Hi,

I am using youtube downloader to download videos.

Suddenly, from today, its not downloading,

it reports,

"D/YTDownload(  740): Got content - parsing...
D/YTDownload(  740): Exception in finding ID: java.lang.Exception: Could not
find download URL or title."

Also, i noticed, in  m.youtube.com new site, the option to choose from
"Browser or Youtube" is not shown.

Only, i have to select old site or goto desktop version, only then it shows.

Is there any way to download youtube videos or youtube player is available.

I am totally struck with the things.
Any help would be useful.

Thanks and Regards,
HarishKumar.V

--~--~---------~--~----~------------~-------~--~----~

3. How to force the on-screen keyboard on HTC Hero

4. Unable to start service intent service not found

5. Why pay Google?

6. how can i MapView my map before attach to window

7. How to use apache commons in my android application