Sockets can be used on networks for two-way communication between two 
machines. It's a really raw and low-level kind of communication where you 
have an input stream for reading what the other machine has to "tell" you 
and an output stream for "telling" something the other machine.

You need to come up with a communication protocol for getting something 
useful out of such a connection. That usually works like that:

You have a so-called socket server. It's a piece of software that waits for 
incoming connection requests from clients and it also usually resides on a 
server machine. The socket server listens to a certain port number of a 
network address. That network address and port number needs to be addressed 
by the client, when it wants to talk to the socket server.

After a connection has been established some kind of negotiation between 
client and server needs to happen. Your client app could for example send 
some authentication credentials in order to log in the user. The server 
sends some acknowledgment on success or an error message as response.

If the login was successful your server could for example directly tell the 
client that there are new messages available.

I suggest reading 
http://docs.oracle.com/javase/tutorial/networking/sockets/index.html for an 
introduction to the Java side of it.

I also strongly suggest that you are making use of secure sockets since you 
are dealing with sensitive data (private conversations, login data). That 
shouldn't go over the net unencrypted. Here is some documentation about 
that: 
http://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html

It is also possible to create a socket server in PHP. But out of experience 
it is not completely suitable for that task. First of all you need to turn 
off the execution timeout for that socket server script (since PHP is meant 
to be executed in terms of short-lived HTTP requests). Second of all PHP is 
not reliable when run for a longer time. I tried to do that in the past and 
it was a huge mistake. The garbage collector has serious problems and after 
an hour or so, your script will terminate.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to