0

I have an server-client application on android which support messaging between clients. ı run server and client program on different emulator on the same computer. when server is listening the port, client try to connect it with these statements.

String serverIpAddresss = "10.0.2.2"; 
InetAddress addr = InetAddress.getByName(serverIpAddresss);
Socket socket = new Socket(addr,REDIRECTED_SERVERPORT);

and before that i redirected 5000:6000 because 5000 is client and 6000 is server's port. new socket line it doesnt work and doesnt create socket. Can anybody help me how to connect client and server and how to communicate with eachothers?

Hakan Serce
  • 11,198
  • 3
  • 29
  • 48
Emre
  • 13
  • 4
  • Instead of "10.0.2.2" use your system's static IP.. and check for INTERNET permission. – user370305 Jul 19 '12 at 06:18
  • Also from command shell on your system, `adb forward tcp:5000 tcp:6000` – user370305 Jul 19 '12 at 06:23
  • if you mean 127.0.0.1 i have tried but it doesnt work too. because all amulators and computer hava it's own internet space so ı have to connect them eacother firstly but i cant. And also i have the permission in my manifest. – Emre Jul 19 '12 at 06:24
  • No, static ip means, your system's IP You can get it via command, `ipconfig` something like, ex. `192.168.1.1` – user370305 Jul 19 '12 at 06:25
  • I have redirect 5000 to 6000 user370305.Now ı am gonna try static ıp. Actually ı am working on a secure networking computer and connected with company domain. Is it possible to this secure domain block my connectşon? – Emre Jul 19 '12 at 06:29
  • No, It's a simple Server-Client architecture with your system so I don't think so, For more information Look at http://stackoverflow.com/questions/11328554/android-connect-to-pcs-localhost-when-debugger-on-mobile-device/11328581#11328581 – user370305 Jul 19 '12 at 06:29
  • On this post they have talked about server program like xampp , do ı need?. I have looking at all stackoverflow post and tried all of them but it doesnt work. Just a simple connection ı need. Please can you tell me what to do for simple connection with an order? – Emre Jul 19 '12 at 06:46
  • check your firewall be turn off – Misagh Aghakhani Oct 07 '12 at 11:44

1 Answers1

0

Add this to your android Manifest File:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

EDIT

The Android emulator connects to the same network as your host computer, but with it's own IP. By default it uses a NAT connection. You should be able to connect.

Check your server's port if it's opened and the firewall rules.

Qsiris
  • 1,143
  • 1
  • 13
  • 27
  • I am working a secure networking computer and ı am connected a company domain so there are some safety rules and some limititaion. I mean there are firewall rules and ı cant fix cous of permission. – Emre Jul 19 '12 at 06:33