Autore Topic: Connessione Socket PC <-> Android  (Letto 1019 volte)

Offline emaborsa

  • Utente normale
  • ***
  • Post: 274
  • Java Developer
  • Respect: +33
    • Google+
    • emaborsa
    • Mostra profilo
    • www.emaborsa.com
  • Dispositivo Android:
    Samsung Galaxy S2
  • Sistema operativo:
    Linux 10 - Win8.1 - Android 4.1.2
Connessione Socket PC <-> Android
« il: 29 Aprile 2012, 01:01:46 CEST »
0
Ciao,
il mio codice lato Server sul PC:

Codice (Java): [Seleziona]
        @Override
        public void run() {
                System.out.println("Listen...");
                try {
                        listenSocket = new ServerSocket(serverPort);
                        clientSocket = listenSocket.accept();
                        if (clientSocket != null && clientSocket.isConnected()) {
                                in = new DataInputStream(clientSocket.getInputStream());
                                out = new DataOutputStream(clientSocket.getOutputStream());
                                handler = new ProtocolHandler(out);
                                while (isRunning && clientSocket != null
                                                && clientSocket.isConnected()) {
                                        String input = in.readUTF();
                                        if (input != null) {
                                                handler.answer(input);
                                        }
                                }
                        }
                }
       

e questo il lato android:

Codice (Java): [Seleziona]
        public void connect() throws UnknownHostException, IOException {
                this.socekt = new Socket(InetAddress.getByName(this.host), PORT);
                this.in = new DataInputStream(this.socekt.getInputStream());
                this.out = new DataOutputStream(this.socekt.getOutputStream());
                this.listener = new Listener();
                this.isConnected = true;
                this.listener.start();
        }

Al momento della chiamata connect() mi lancia questa eccezione dalla riga dove creo il nuovo socket.
Non capisco il problema....

Codice: [Seleziona]
04-29 00:56:21.945: ERROR/com.emaborsa.activities.Main(20259):     at libcore.io.IoBridge.socket(IoBridge.java:573)
04-29 00:56:21.945: ERROR/com.emaborsa.activities.Main(20259):     at com.emaborsa.core.RemotePlayer.connect(RemotePlayer.java:59)
04-29 00:56:21.945: ERROR/com.emaborsa.activities.Main(20259):     at com.emaborsa.activities.Main$1$1.onClick(Main.java:78)
04-29 00:56:21.945: ERROR/com.emaborsa.activities.Main(20259):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
04-29 00:56:21.945: ERROR/com.emaborsa.activities.Main(20259):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
04-29 00:56:21.945: ERROR/com.emaborsa.activities.Main(20259):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
04-29 00:56:21.945: ERROR/com.emaborsa.activities.Main(20259): Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)
04-29 00:56:21.945: ERROR/com.emaborsa.activities.Main(20259):     at libcore.io.Posix.socket(Native Method)
04-29 00:56:21.945: ERROR/com.emaborsa.activities.Main(20259):     at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)
04-29 00:56:21.945: ERROR/com.emaborsa.activities.Main(20259):     at libcore.io.IoBridge.socket(IoBridge.java:558)

Offline emaborsa

  • Utente normale
  • ***
  • Post: 274
  • Java Developer
  • Respect: +33
    • Google+
    • emaborsa
    • Mostra profilo
    • www.emaborsa.com
  • Dispositivo Android:
    Samsung Galaxy S2
  • Sistema operativo:
    Linux 10 - Win8.1 - Android 4.1.2
Re:Connessione Socket PC <-> Android
« Risposta #1 il: 29 Aprile 2012, 01:09:59 CEST »
0
ops...scusate.... ho dimenticato la permission nel Manifest.