Problem with using socket to connect with PC
<p>I'm trying to connect my phone with my notebook using WiFi. Both devices are connected to one network. Notebook has IP 192.168.1.35 so i tried to connect with that IP through smart phone (firewall is off). Here's the code:</p>

<pre><code>package org.me.androidapp;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        try {
            Toast.makeText(this.getApplicationContext(), "OK", Toast.LENGTH_LONG).show();
            Socket socket = new Socket("192.168.1.35", 9999);
            PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);
            out.println("dupa");
            socket.close();
        } catch (UnknownHostException ex) {
            Toast.makeText(this.getApplicationContext(), "Nie odnaleziono hosta", Toast.LENGTH_LONG).show();
            Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Toast.makeText(this.getApplicationContext(), ex.toString(), Toast.LENGTH_LONG).show();
            Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}
</code></pre>

<p>Im using this code (written in python) as server:</p>

<pre><code>import socket

_connector = None
_running = True

_host = 'localhost'
_port = '9999'
_maxClient = 999

debug = True
_policyFile = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd"&gt;&lt;allow-access-from domain="*" to-ports="*" secure="false" /&gt;&lt;site-control permitted-cross-domain-policies="master-only" /&gt;&lt;/cross-domain-policy&gt;'

## Trace debugging messages.
#  @param aString String to be printed.
def printd( aString ):
    if debug:
        print aString

_connector = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
_connector.bind ( ( str(_host), int(_port) ) )
_connector.listen ( int(_maxClient) )
_running = True

while _running:
  printd('Running on port ' + _port + ' ... ')
  channel, details = _connector.accept()

  if _running:
      printd( 'New connection with: ' + str(details) )
      channel.setblocking( 1 )
      recvData = channel.recv(2000)

      if("policy-file-request" in recvData):
         channel.send(_policyFile)

      printd( 'host: ' + str(details[0]) )
      printd( 'port: ' + str(details[1]) )
      printd( 'port: ' + str(int(details[1])) )

      channel.close()
</code></pre>

<p>Im testing this app on my phone because im not sure how to configure emulator (any help? :) ). Phone shows error "Java.Net.ConnectionError localhost/192.168.1.1:9999 - connection refused". Im wondering also why it shows IP 192.168.1.1... </p>

<p>Please help,
Chris</p>
