Socket Programming

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Postby qamerfarooq » Thu Jan 17, 2008 6:48 am

You should opt for the option-1. Because client should have server's IP which is (192.168.52.34)
1) ---------------------------------------------------------
server IP address: 127.0.0.1
client IP address: 192.168.52.34
Qamer Farooq
End 2 End Solution Providers
http://www.e2esp.com
qamerfarooq
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jan 11, 2008 6:07 am
Location: Pakistan

Top

Postby aBin » Thu Jan 17, 2008 2:19 pm

Thanks :)
qamerfarooq wrote:You should opt for the option-1. Because client should have server's IP which is (192.168.52.34)
1) ---------------------------------------------------------
server IP address: 127.0.0.1
client IP address: 192.168.52.34
aBin
Freshman
Freshman
 
Posts: 2
Joined: Tue Nov 27, 2007 5:59 am

Postby GeorgieYuan » Wed Mar 05, 2008 7:24 pm

aBin wrote:Thanks :)
qamerfarooq wrote:You should opt for the option-1. Because client should have server's IP which is (192.168.52.34)
1) ---------------------------------------------------------
server IP address: 127.0.0.1
client IP address: 192.168.52.34


Hi all,

I found that when the Server is an Android Server, the socket communication(TCP/UDP) will be failed, any suggestion on this issue?

Regards.
GeorgieYuan
Freshman
Freshman
 
Posts: 3
Joined: Mon Mar 03, 2008 6:36 pm

Postby qamerfarooq » Thu Mar 06, 2008 6:57 am

GeorgieYuan wrote:
Hi all,

I found that when the Server is an Android Server, the socket communication(TCP/UDP) will be failed, any suggestion on this issue?

Regards.


In case your server is on Android then you need to follow the following steps to make your server available on network:

1- Lets say your server is listening on port number 6100 in android.

2- Forward the ports using the following command, so you can connect to android from localhost
Code: Select all
adb forward tcp:6100 tcp:6100


3- Now you can connect to this port from localhost but not from the network, it means you can connect using localhost:6100 from your desktop computer but not with the IP (192.168.0.1:6100 )

    telnet localhost 6100 OK
    telnet 192.168.0.1 6100 Failed

4- An extra step is needed for network access.
Use some proxy server which can listen on 192.168.0.140:6100 and forward the data to localhost:6100 (which is your android server)
Qamer Farooq
End 2 End Solution Providers
http://www.e2esp.com
qamerfarooq
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jan 11, 2008 6:07 am
Location: Pakistan

Postby GeorgieYuan » Thu Mar 06, 2008 11:03 am

qamerfarooq wrote:
GeorgieYuan wrote:
Hi all,

I found that when the Server is an Android Server, the socket communication(TCP/UDP) will be failed, any suggestion on this issue?

Regards.


In case your server is on Android then you need to follow the following steps to make your server available on network:

1- Lets say your server is listening on port number 6100 in android.

2- Forward the ports using the following command, so you can connect to android from localhost
Code: Select all
adb forward tcp:6100 tcp:6100


3- Now you can connect to this port from localhost but not from the network, it means you can connect using localhost:6100 from your desktop computer but not with the IP (192.168.0.1:6100 )

    telnet localhost 6100 OK
    telnet 192.168.0.1 6100 Failed
4- An extra step is needed for network access.
Use some proxy server which can listen on 192.168.0.140:6100 and forward the data to localhost:6100 (which is your android server)


Follow the above steps, I have fixed this problem and it's works fine now. I'm using the TCP proxy-stcppipe.
Thanks for your help!
GeorgieYuan
Freshman
Freshman
 
Posts: 3
Joined: Mon Mar 03, 2008 6:36 pm

Postby inter » Sat Mar 08, 2008 5:27 pm

Hi,do you can do it by using XMPP ? (a mini chat application between mobilephone ) .So how to test it

Thanks
inter
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 21, 2008 10:13 am

Top

Postby plusminus » Sat Mar 08, 2008 6:00 pm

Hello inter,

... XMPP is gone since m5 :!: ...

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 rakolta » Wed Mar 12, 2008 6:22 am

1) If XMPP is now gone, what's the best way to send binary data from mobilephone to mobilephone?
2) Will the mobilephones using the Android OS have unique IP addresses?
3) If so, can TCP/IP or UDP/IP be used for direct communication between mobilephones?

Thanks
rakolta
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Mar 12, 2008 6:10 am

Postby saiko6996 » Thu Mar 27, 2008 1:11 pm

Hi!

I am using android like a TCPclient and a java application like a TCPserver. It works fine sending and receiving Strings, int, double,..... The problem is when I want to send from server and read in the client an Object of this class:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class ElementsClass implements Serializable{
  2.  
  3.        
  4.  
  5.                 private String element1= null;
  6.  
  7.                 private String element2= null;
  8.  
  9.                
  10.  
  11.         public ElementsClass (){
  12.  
  13.                
  14.  
  15.         }
  16.  
  17.        
  18.  
  19.         public void setLE1(String e1){this.element1= e1;}
  20.  
  21.         public void setE2(String e2){this.element2= e2;}
  22.  
  23.         public String getE1(){return element1;}
  24.  
  25.         public String getE2(){return element2;}
  26.  
  27.        
  28.  
  29. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


This is the server(Java App):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ois = new ObjectInputStream(client.getInputStream());
  2.  
  3.       oos = new ObjectOutputStream(client.getOutputStream());
  4.  
  5.       ElementsClass aux= new ElementClass();
  6.  
  7.       aux.setE1("first");
  8.  
  9.       aux.setE2("second");
  10.  
  11.       oos.writeObject(aux);
  12.  
  13.       oos.flush();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


This is the client class(Android App):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     oos = new ObjectOutputStream(socket.getOutputStream());
  2.  
  3.       ois = new ObjectInputStream(socket.getInputStream());
  4.  
  5.       Object aux= ois.readObject();
  6.  
  7.       ElementsClass element= (ElementsClass )aux;
Parsed in 0.036 seconds, using GeSHi 1.0.8.4



Whats the problem???

The connection works fine, the problem is reading the object. I follow the server and client arquitecture of this web: http://java.sun.com/developer/technicalArticles/ALT/sockets/
saiko6996
Freshman
Freshman
 
Posts: 6
Joined: Tue Feb 19, 2008 7:41 pm

Postby bonny » Mon Apr 28, 2008 8:58 am

Hello.
I have an application that use the sip protocol and I need to know how to reach the emulator doing a call from an extern client; when android act as a client and another computer as a server, everything works fine, but when Android is a Server, I cannot reach it, there is no forwarding of sip calls from the host to android.
I tried adb forward without significant results. How can I make android listening to a port, known at run-time?
bonny
Junior Developer
Junior Developer
 
Posts: 19
Joined: Fri Apr 11, 2008 2:08 pm

need help on scoket programing in Android

Postby android_dj » Sun Sep 28, 2008 6:48 pm

Hi Friends

I could not able to find a solution on socket programming. I am getting exception like "Unknown host name".

Example:

Socket sc = new Socket("mycompany.com",8080);

would any one tell me what steps should i follow, please?
android_dj
Freshman
Freshman
 
Posts: 3
Joined: Sun Sep 28, 2008 6:39 pm

Postby plusminus » Mon Sep 29, 2008 3:59 am

Did you add the uses-Permission INTERNET in the AndroidManifest.xml :?:

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 android_dj » Mon Sep 29, 2008 5:31 am

plusminus wrote:Did you add the uses-Permission INTERNET in the AndroidManifest.xml :?:

Regards,
plusminus


Thank you.

I added like this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    package="net.mobiquest">
  6.  
  7.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  8.  
  9.         <activity android:name=".MyApp" android:label="@string/app_name">
  10.  
  11.     <uses-permission android:name="android.permission.INTERNET" />    
  12.  
  13.             <intent-filter>
  14.  
  15.                 <action android:name="android.intent.action.MAIN" />
  16.  
  17.                 <category android:name="android.intent.category.LAUNCHER" />
  18.  
  19.             </intent-filter>
  20.  
  21.         </activity>
  22.  
  23.     </application>
  24.  
  25. </manifest>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
Last edited by android_dj on Mon Sep 29, 2008 7:33 am, edited 1 time in total.
android_dj
Freshman
Freshman
 
Posts: 3
Joined: Sun Sep 28, 2008 6:39 pm

Postby plusminus » Mon Sep 29, 2008 5:42 am

You're welcome :)
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 android_dj » Mon Sep 29, 2008 7:37 am

Last edited by android_dj on Tue Sep 30, 2008 5:24 am, edited 1 time in total.
android_dj
Freshman
Freshman
 
Posts: 3
Joined: Sun Sep 28, 2008 6:39 pm

Top
PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 4 guests