Ulf Dittmer wrote:This looks like a strange design. The different parts of an Android application don't communicate with one another using sockets - they use Android mechanisms like startActivityForResult, AsncTask or a common Application subclass. What exactly are you trying to achieve?
As an aside, you should read Don't println to a Socket. Since the code uses "readLine" it is potentially vulnerable to this problem (although this is not an issue if both client and server run in the same JVM).
Swastik Dey wrote:
Swastik
Swastik Dey wrote:The exception is probably at this line double msgValue = Integer.parseInt(actVal); It means you are getting some response but actVal can't be converted to numeric. So just check what you are getting as response, and what you are getting in actVal after the split operations.
Swastik
Swastik Dey wrote:To be honest, even I am also confused. Earlier you had said your android app is supposed to connect to a desktop app, so as per me that should be server, correct me if I am wrong.
Swastik
Swastik Dey wrote:As far as my knowledge goes, to connect to a server you need an ip address/dns. So does the desktop app know anything about phone's ip? Typically phones get a dynamic ip address. And what's wrong making it a client? Send a message to the desktop app(server), server sends the xml back to you. Now process that xml. Your xml parsing does not also seem to be too good. Why not use standard parsers like sax/dom?
Swastik Dey wrote:As far as my knowledge goes, to connect to a server you need an ip address/dns. So does the desktop app know anything about phone's ip? Typically phones get a dynamic ip address. And what's wrong making it a client? Send a message to the desktop app(server), server sends the xml back to you. Now process that xml. Your xml parsing does not also seem to be too good. Why not use standard parsers like sax/dom?
Swastik
Swastik Dey wrote:As far as my knowledge goes, to connect to a server you need an ip address/dns. So does the desktop app know anything about phone's ip? Typically phones get a dynamic ip address. And what's wrong making it a client? Send a message to the desktop app(server), server sends the xml back to you. Now process that xml. Your xml parsing does not also seem to be too good. Why not use standard parsers like sax/dom?
Ulf Dittmer wrote:I notice that the code still has the Don't println to a Socket bug (on both ends of the connection, actually).
str = in.readLine();
Swastik Dey wrote:Madhu,
Your code worked for me without any issues. Make sure the 1)server ip address you are using in client is correct. 2) Server is running. 3) You have added the required permission i.e.
android.permission.INTERNET in android manifest file.
Ulf Dittmer wrote:I notice that the code still has the Don't println to a Socket bug (on both ends of the connection, actually).
Ulf Dittmer wrote:OK, so one only side of the communication actually runs on the phone. In that case the article I linked to is indeed relevant.
It would be the client that runs on the phone, as there generally is no way for desktop apps to reliably access a server process on a phone.
(Note that you need to use the "magic" IP address 10.0.2.2 to access the host if the code runs on the emulator instead of an actual device.)
Consider Paul's rocket mass heater. |