TCP Sockets

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

TCP Sockets

Postby hugopicado » Fri Dec 14, 2007 12:06 pm

Hi.

I can't make TCP sockets work. I'm doing this:

Server side:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.             try {
  2.  
  3.                 ss = new ServerSocket(4444);
  4.  
  5.                 sc = ss.accept();
  6.  
  7.             }
  8.  
  9.             catch (IOException e) {
  10.  
  11.                 label.setText("erro1");
  12.  
  13.             }
  14.  
  15.            
  16.  
  17.             label.setText("connected");
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Client side:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.             try {
  2.  
  3.                 sc = new Socket(myIP,4444);
  4.  
  5.             }
  6.  
  7.             catch (IOException e) {
  8.  
  9.                 label.setText("erro2");
  10.  
  11.             }
  12.  
  13.            
  14.  
  15.             label.setText("connected");
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


I'm working in one machine with two emulators running. myIP is an IP from one of my interfaces since I read somewhere that android has problems with "localhost" and "127.0.0.1".

The server just blocks before I can do anything else.
What am I doing wrong?

Thanks in advance.
Best regards,
Hugo.
hugopicado
Freshman
Freshman
 
Posts: 8
Joined: Fri Dec 14, 2007 2:31 am

Top

Postby metaxxa3 » Fri Dec 14, 2007 3:22 pm

I wrote something code. I cannot speak very good in English. Sorry.
This code is good for client to server communicate.
I'm trying send an answer to android client (emulator), but I cannot.
I don't know how to find something start point for waiting socket's communication. I've put into onCreate method, but I've caught an exception (NullPointException). Any debug method in this case?
original source inherited from java.sun.com (knockknock example)


The files:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import java.io.IOException;
  3.  
  4. import java.net.ServerSocket;
  5.  
  6.  
  7.  
  8. public class KKMultiServer {
  9.  
  10.         public static void main(String[] args) throws IOException {
  11.  
  12.                 ServerSocket serverSocket = null;
  13.  
  14.                 boolean listening = true;
  15.  
  16.  
  17.  
  18.                 try {
  19.  
  20.                         while (listening) {
  21.  
  22.                                 if (serverSocket == null) {
  23.  
  24.                                         serverSocket = new ServerSocket(4444);
  25.  
  26.                                 }
  27.  
  28.                                 new KKMultiServerThread(serverSocket.accept()).start();
  29.  
  30.                         }
  31.  
  32.                 } catch (IOException e) {
  33.  
  34.                         System.err.println("Could not listen on port: 4444.");
  35.  
  36.                         serverSocket.close();
  37.  
  38.                         System.exit(-1);
  39.  
  40.                 }
  41.  
  42.  
  43.  
  44.         }
  45.  
  46. }
  47.  
  48.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4





Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import java.io.BufferedReader;
  3.  
  4. import java.io.IOException;
  5.  
  6. import java.io.InputStreamReader;
  7.  
  8. import java.io.PrintWriter;
  9.  
  10. import java.net.Socket;
  11.  
  12.  
  13.  
  14. public class KKMultiServerThread extends Thread {
  15.  
  16.         private Socket socket = null;
  17.  
  18.  
  19.  
  20.     public KKMultiServerThread(Socket socket) {
  21.  
  22.         super("KKMultiServerThread");
  23.  
  24.         this.socket = socket;
  25.  
  26.     }
  27.  
  28.  
  29.  
  30.     public void run() {
  31.  
  32.  
  33.  
  34.         try {
  35.  
  36.             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
  37.  
  38.             BufferedReader in = new BufferedReader(
  39.  
  40.                                     new InputStreamReader(
  41.  
  42.                                     socket.getInputStream()));
  43.  
  44.  
  45.  
  46.             String inputLine, outputLine;
  47.  
  48.             while ((inputLine = in.readLine()) != null) {
  49.  
  50.                 System.out.println(inputLine);
  51.  
  52.                 outputLine = String.valueOf(inputLine.length());
  53.  
  54.                 out.println(outputLine);
  55.  
  56.                 if (outputLine.equals("5"))  //only small criteria avoid neverending cycle.
  57.  
  58.                     break;
  59.  
  60.             }
  61.  
  62.             out.close();
  63.  
  64.             in.close();
  65.  
  66.             socket.close();
  67.  
  68.  
  69.  
  70.         } catch (IOException e) {
  71.  
  72.             e.printStackTrace();
  73.  
  74.         }
  75.  
  76.     }
  77.  
  78. }
  79.  
  80.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4



And android client:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. import java.io.BufferedReader;
  5.  
  6. import java.io.IOException;
  7.  
  8. import java.io.PrintWriter;
  9.  
  10. import java.net.Socket;
  11.  
  12. import java.net.UnknownHostException;
  13.  
  14.  
  15.  
  16. import android.app.Activity;
  17.  
  18. import android.os.Bundle;
  19.  
  20. import android.view.View;
  21.  
  22. import android.view.View.OnClickListener;
  23.  
  24. import android.widget.Button;
  25.  
  26. import android.widget.EditText;
  27.  
  28.  
  29.  
  30. public class LocationSend extends Activity implements OnClickListener {
  31.  
  32.  
  33.  
  34.         private final String ipAddress = "10.0.0.1";  // ip of server pc.
  35.  
  36.         private final int port = 4444;
  37.  
  38.         EditText mLocation;
  39.  
  40.         Button mConfirm;
  41.  
  42.         Socket kkSocket = null;
  43.  
  44.         PrintWriter out = null;
  45.  
  46.         BufferedReader in = null;
  47.  
  48.  
  49.  
  50.         /** Called when the activity is first created. */
  51.  
  52.         @Override
  53.  
  54.         public void onCreate(Bundle icicle) {
  55.  
  56.                 super.onCreate(icicle);
  57.  
  58.                 setContentView(R.layout.main);
  59.  
  60.                 mLocation = (EditText) findViewById(R.id.location);
  61.  
  62.                 mConfirm = (Button) findViewById(R.id.confirm);
  63.  
  64.  
  65.  
  66.                 mConfirm.setOnClickListener(this);
  67.  
  68.  
  69.  
  70.                 try {
  71.  
  72.                         kkSocket = new Socket(ipAddress, port);
  73.  
  74.                 } catch (UnknownHostException e) {
  75.  
  76.                         errorMessage("Unknown host" + ipAddress);
  77.  
  78.                 } catch (IOException e) {
  79.  
  80.                         errorMessage("Couldn't get I/O for the connection to: " + ipAddress);
  81.  
  82.                 }
  83.  
  84.  
  85.  
  86.         }
  87.  
  88.  
  89.  
  90.         private void errorMessage(String msg) {
  91.  
  92.                 this.showAlert("Error!", msg, "OK", true);
  93.  
  94.                 System.err.println("Error:" + msg);
  95.  
  96.         }
  97.  
  98.  
  99.  
  100.         public void onClick(View view) {
  101.  
  102.                
  103.  
  104.                 try {
  105.  
  106.  
  107.  
  108.                         out = new PrintWriter(kkSocket.getOutputStream(), true);
  109.  
  110.                         out.println(mLocation.getText());
  111.  
  112.                        
  113.  
  114.                 } catch (UnknownHostException e) {
  115.  
  116.                         errorMessage("Unknown host" + ipAddress);
  117.  
  118.                 } catch (IOException e) {
  119.  
  120.                         errorMessage("Couldn't get I/O for the connection to: " + ipAddress);
  121.  
  122.  
  123.  
  124.                 }
  125.  
  126.  
  127.  
  128.         }
  129.  
  130.  
  131.  
  132.         @Override
  133.  
  134.         protected void onPause() {
  135.  
  136.                 // TODO Auto-generated method stub
  137.  
  138.                 super.onPause();
  139.  
  140.  
  141.  
  142.                 try {
  143.  
  144.                         kkSocket.close();
  145.  
  146.                 } catch (IOException e) {
  147.  
  148.                         errorMessage("Couldn't close I/O for the connection to: "
  149.  
  150.                                         + ipAddress);
  151.  
  152.                 }
  153.  
  154.  
  155.  
  156.         }
  157.  
  158.  
  159.  
  160.         @Override
  161.  
  162.         protected void onResume() {
  163.  
  164.                 super.onResume();
  165.  
  166.                 try {
  167.  
  168.                         kkSocket = new Socket(ipAddress, port);
  169.  
  170.                 } catch (UnknownHostException e) {
  171.  
  172.                         errorMessage("Unknown host " + ipAddress);
  173.  
  174.                 } catch (IOException e) {
  175.  
  176.                         errorMessage("Couldn't get I/O for the connection to: " + ipAddress);
  177.  
  178.                 }
  179.  
  180.         }
  181.  
  182.  
  183.  
  184.         @Override
  185.  
  186.         protected void onStop() {
  187.  
  188.  
  189.  
  190.                 super.onStop();
  191.  
  192.                 try {
  193.  
  194.                         if (kkSocket != null) {
  195.  
  196.                                 if (kkSocket.isConnected())
  197.  
  198.                                         kkSocket.close();
  199.  
  200.                         }
  201.  
  202.                 } catch (IOException e) {
  203.  
  204.                         errorMessage("Couldn't close I/O for the connection to: "
  205.  
  206.                                         + ipAddress);
  207.  
  208.  
  209.  
  210.                 }
  211.  
  212.         }
  213.  
  214.  
  215.  
  216. }
  217.  
  218.  
Parsed in 0.047 seconds, using GeSHi 1.0.8.4
metaxxa3
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 10, 2007 3:35 pm

Postby plusminus » Fri Dec 14, 2007 4:43 pm

Hello Guys,

TCP seems to be a kind of problem !

:arrow: For now I succeeded, to send data between two UDP-Connections within the emulator. The Log:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. D/UDP(1515): S: Connecting...
  2. D/UDP(1515): S: Receiving...
  3. D/UDP(1515): C: Connecting...
  4. D/UDP(1515): C: Sending: 'Hello from Client'
  5. D/UDP(1515): S: Received: 'Hello from Client'
  6. D/UDP(1515): S: Done.
  7. D/UDP(1515): C: Sent.
  8. D/UDP(1515): C: Done.
Parsed in 0.065 seconds, using GeSHi 1.0.8.4


I'll have a look for some working TCP-Stuff :!:

The code below will be put into an tutorial right now.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class UDPConnection extends Activity {
  2.     /** Called when the activity is first created. */
  3.     @Override
  4.     public void onCreate(Bundle icicle) {
  5.         super.onCreate(icicle);
  6.         setContentView(R.layout.main);
  7.        
  8.         Thread sThread = new Thread(new Server());
  9.         Thread cThread = new Thread(new Client());
  10.        
  11.         sThread.start();
  12.         try {
  13.                         Thread.sleep(500);
  14.                 } catch (InterruptedException e) { }
  15.        
  16.                 cThread.start();
  17.     }
  18. }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Server implements Runnable{
  2.         public static final String SERVERIP = "127.0.0.1";
  3.         public static final int SERVERPORT = 4444;
  4.                
  5.         @Override
  6.         public void run() {
  7.                 try {
  8.                         Log.d("UDP", "S: Connecting...");
  9.                         InetAddress serverAddr = InetAddress.getByName(SERVERIP);
  10.                         DatagramSocket socket = new DatagramSocket(SERVERPORT,serverAddr);
  11.                         byte[] buf = new byte[17];
  12.                         DatagramPacket packet = new DatagramPacket(buf, buf.length);
  13.                         Log.d("UDP", "S: Receiving...");
  14.                         socket.receive(packet);
  15.                         Log.d("UDP", "S: Received: '" + new String(packet.getData()) + "'");
  16.                         Log.d("UDP", "S: Done.");
  17.                 } catch (Exception e) {
  18.                         Log.e("UDP", "S: Error", e);
  19.                 }
  20.         }
  21. }
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Client implements Runnable {
  2.         @Override
  3.         public void run() {
  4.                 try {
  5.                         Log.d("UDP", "C: Connecting...");
  6.                         DatagramSocket socket = new DatagramSocket();
  7.                         byte[] buf = ("Hello from Client").getBytes();
  8.                         InetAddress serverAddr = InetAddress.getByName(Server.SERVERIP);
  9.                         DatagramPacket packet = new DatagramPacket(buf, buf.length,     serverAddr, Server.SERVERPORT);
  10.                         Log.d("UDP", "C: Sending: '" + new String(buf) + "'");
  11.                         socket.send(packet);
  12.                         Log.d("UDP", "C: Sent.");
  13.                         Log.d("UDP", "C: Done.");
  14.                 } catch (Exception e) {
  15.                         Log.e("UDP", "C: Error", e);
  16.                 }
  17.         }
  18. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby metaxxa3 » Mon Dec 17, 2007 10:50 am

Hi!

Is there any updates on TCP sockets? I would like to create pc server (in java), and android client.

Cheers!
metaxxa3
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 10, 2007 3:35 pm

Postby hugopicado » Mon Dec 17, 2007 4:35 pm

I'm working on that. Soon I hope to have news :)
hugopicado
Freshman
Freshman
 
Posts: 8
Joined: Fri Dec 14, 2007 2:31 am

Postby hugopicado » Fri Dec 21, 2007 10:40 am

First of all if you want to use different computers/processes and not the same emulator you should redirect the ports from host to emulator starting the emulator with the QEMU redir option. This allows the computer to redirect incoming connections from the host to the running emulator.

Example: emulator qemu -redir tcp:4444::4444

Note: you can use adb forward to the the same thing when the emulator is running (maybe this is useful for Eclipse users).

Anyway...

Now you should start your server thread. But you should notice that if you run the "netstat -at" command (under Linux) you'll see that the host is listening on the address 127.0.0.1. But this address does mean nothing to the remote computer so is that why you cannot establish a connection running a TCP Android Server.

If you do the similar experience with UDP sockets, you will notice that the host is listening on the address 0.0.0.0 (i.e. all available addresses) and in fact you can receive packets from a remote computer running an Android Client. The problem with UDP is that packets come with the Source Address 10.0.2.2, which are the address of the internal interface of the emulator and this does mean nothing to the emulator which received the message and so it cannot reply.

About the localhost/127.0.0.1 problem, this happens because it considers 127.0.0.1/localhost it's own loopback interface, instead of the one of the computer, so you should really use any other interface address (e.g. eth0, wlan0, etc)

Hope to clarify.

Regards,
hp.
hugopicado
Freshman
Freshman
 
Posts: 8
Joined: Fri Dec 14, 2007 2:31 am

Top

Postby Tracy Xiang » Sat Dec 29, 2007 7:16 am

Hi,
I have been in trouble with C/S for a couple of days,and still,I have no idea.
Would somebody provide a tutorial about how to establish a connection with socket?
Appreciate!

Regards
Tracy
Tracy Xiang
Freshman
Freshman
 
Posts: 3
Joined: Fri Dec 28, 2007 5:37 pm
Location: China

Log output viewing?

Postby sai » Tue Jun 03, 2008 9:14 am

Hi PlusMinus,

In your post above, you have pasted the logs, where do we see them?
In the Console window (when using Eclipse) or
using "adb logcat" (Verbose or Debug mode) on the command-line?

Thanks,
Sai.
sai
Freshman
Freshman
 
Posts: 3
Joined: Sun Jun 01, 2008 4:34 am

Re: Log output viewing?

Postby zjsst1214 » Sun Jun 15, 2008 5:06 pm

sai wrote:Hi PlusMinus,

In your post above, you have pasted the logs, where do we see them?
In the Console window (when using Eclipse) or
using "adb logcat" (Verbose or Debug mode) on the command-line?

Thanks,
Sai.



Hi,Sai

You can see the log in the LogCat.If you use eclipse you can see it in Window->Show View->Others->Android->LogCat
纵马天涯
zjsst1214
Freshman
Freshman
 
Posts: 7
Joined: Fri Jun 13, 2008 7:42 am

Any news from TCP Server Sockets problem?

Postby rmcavalcante » Thu Sep 11, 2008 11:07 am

PlusMinus,

I have read you would try to provide a solution for the TCPSocket problem.
Have you made it?

I have a problem with a class cast exception when I try to get the InputStream from a java.net.Socket.
Logcat shows a ClassCastException.
But when I try to run in J2SE, not in android, it works smoothly!
Then I realize that Android is using another implementation for the InputStream, it is a org.apache.harmony.luni.net.SocketInputStream
My android SDK is android-sdk-windows-0.9_beta
My eclipse is Version: 3.4.0
Build id: I20080617-2000 + ADT plugin correctly installed and updated (there is none so far :-D )
I try to debug my application but it is not stopping where it should.
Does anyone else have problems debugging with this android release?

Here goes my code.
peer = new java.net.Socket(address, this.port);
//the problem happens here
dataIn = (InputStream)peer.getInputStream();
dataOut = (OutputStream)peer.getOutputStream();
//The 1st cast raises a ClassCastException with org.apache.harmony.luni.net.SocketInputStream
//Does anyone can provide an alternative, a workaround?

Thanks in advance.
rmcavalcante
Freshman
Freshman
 
Posts: 7
Joined: Thu Sep 11, 2008 10:48 am

Postby nithin11 » Mon Jun 22, 2009 5:11 am

Hi to all..

TCP sockets works fine for me... In my application emulator connect with my server.. I used TCP sockets..
But one thing is the local host i.e. "127.0.0.1" is not worked... and but "192.168.1.1" is works fine...

Thank You
Nithin
nithin11
Developer
Developer
 
Posts: 36
Joined: Mon Mar 09, 2009 5:14 am
Location: India

Postby hackroid » Mon Mar 22, 2010 7:15 am

Hi Nithin,

Were you able to receive messages from the server also?

~Andy
hackroid
Freshman
Freshman
 
Posts: 2
Joined: Sun Mar 21, 2010 10:07 pm

Postby minigun » Thu Mar 25, 2010 9:49 pm

First of all thanks to all you guys, I've learned a lot from you, especially PlusMinus :)

Now while PlusMinus told TCP is kind of problematic, I've started working on network with UDP.
Sending packets was fine, but when I tried receiving socket stalled and never got anything.
(Like the issue on this thread UDP receive problem )

After two weeks I gave up and tried the most simple Java TCP client socket I found on the net,
and it worked like a magic !

The code is as follows...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class TCPTester extends Activity {
  3.        
  4.     private static TextView txtSendStatus;
  5.  
  6.    /** Called when the activity is first created. */
  7.    @Override
  8.    public void onCreate(Bundle savedInstanceState) {
  9.        super.onCreate(savedInstanceState);
  10.        
  11.        setContentView(R.layout.main);  // Give a layout XML instead of a View object
  12.        
  13.        initControls();
  14.  
  15.  
  16.        String sentence = "TCP Test #1n";
  17.        String modifiedSentence;
  18.  
  19.        try {
  20.  
  21.            Socket clientSocket = new Socket("192.168.1.66", 4444);
  22.            DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
  23.            BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  24.            printScr("TCP Connected.");
  25.            
  26.            outToServer.writeBytes(sentence + 'n');
  27.            modifiedSentence = inFromServer.readLine();
  28.            printScr(modifiedSentence);
  29.            printScr("TCP Success !!!");
  30.  
  31.            clientSocket.close();
  32.            
  33.        } catch (Exception e) {
  34.            printScr("TCP Error: " + e.toString());
  35.        }
  36.        
  37.      
  38.    }
  39.    
  40.  
  41.    private void initControls()
  42.    {
  43.           txtSendStatus = (TextView)findViewById(R.id.txtSendStatus);
  44.    }
  45.  
  46.    public static void printScr(String message)
  47.    {
  48.            txtSendStatus.append( "n" + message );
  49.    }
  50.  
  51.  
Parsed in 0.041 seconds, using GeSHi 1.0.8.4


It is that simple and works fine, but I need to say again that I use SDK 1.5 and may work different
on other SDK versions.

Now I have just one issue with this TCP client, that is when we connect to the server with
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Socket clientSocket = new Socket("192.168.1.66", 4444);
  2.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

it opens two client connection on server, so when you send a packet to the server, server gets two
copy of that packet while server has two client connections.

I couln't figured out why, but a workaround may be to close the second TCP connection on the server side,
If you find please inform me :)
minigun
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Mar 25, 2010 9:23 pm

Postby emedina » Mon Mar 29, 2010 3:44 am

Hi to all

Simple TCP Client

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         private void loadClientTCP()
  3.  
  4.         {
  5.  
  6.                 // TODO Auto-generated method stub
  7.  
  8.                 //System.out.println("Hola Mundo");
  9.  
  10.                 String server="192.168.1.250";
  11.  
  12.                 int port=55555;
  13.  
  14.                 Library.trace(" socket "+server+ " "+port);
  15.  
  16.                
  17.  
  18.                 try {
  19.  
  20.                         Socket sk=new Socket(server,port);
  21.  
  22.                         BufferedReader entrada=new BufferedReader(
  23.  
  24.                                                         new InputStreamReader(sk.getInputStream()));
  25.  
  26.                         PrintWriter salida=new PrintWriter(
  27.  
  28.                                                         new OutputStreamWriter(sk.getOutputStream()),true
  29.  
  30.                                                         );
  31.  
  32.                        
  33.  
  34.                         Library.trace("enviando...");
  35.  
  36.                         salida.println("Hola Mundo");
  37.  
  38.                        
  39.  
  40.                         Library.trace("recibiendo ... "+entrada.readLine());
  41.  
  42.                         //sk.close();
  43.  
  44.                 } catch (Exception e) {
  45.  
  46.                         // TODO: handle exception;
  47.  
  48.                         Library.trace("error "+e.toString());
  49.  
  50.                 }
  51.  
  52.         }
  53.  
  54.  
  55.  
  56.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.emedinaa.example.utils;
  3.  
  4.  
  5.  
  6. import android.util.Log;
  7.  
  8.  
  9.  
  10. public class Library
  11.  
  12. {
  13.  
  14.         public static void trace(String s)
  15.  
  16.         {
  17.  
  18.                 Log.v("console", s);
  19.  
  20.         }
  21.  
  22. }
  23.  
  24.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

Manifest >>>>
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.      package="com.emedinaa.example"
  7.  
  8.      android:versionCode="1"
  9.  
  10.      android:versionName="1.0">
  11.  
  12.      <uses-permission android:name="android.permission.INTERNET" />
  13.  
  14.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  15.  
  16.         <activity android:name=".Skt001"
  17.  
  18.                  android:label="@string/app_name">
  19.  
  20.             <intent-filter>
  21.  
  22.                 <action android:name="android.intent.action.MAIN" />
  23.  
  24.                 <category android:name="android.intent.category.LAUNCHER" />
  25.  
  26.             </intent-filter>
  27.  
  28.         </activity>
  29.  
  30.  
  31.  
  32.     </application>
  33.  
  34.  
  35.  
  36.  
  37.  
  38. </manifest>
  39.  
  40.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4



Best regards
Android is Cool
emedina
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Mar 29, 2010 3:27 am
Location: Perú

Postby himym » Mon Mar 29, 2010 10:31 am

I also have trouble establishing a SocketConnection to some Server in the Internet.
When I do it the way emedina did it, but instead of the localIP I put the Internet-IP of my PC which operates like a server. I receive a "java.net.SocketException: The operation timed out". I tried it with several ports, also the 80, but I always receive that message. Can anybody help me on this, please?

Thanks
himym
Developer
Developer
 
Posts: 33
Joined: Sun Oct 18, 2009 9:50 am

Top
Next

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 5 guests