-1

I want my PHP server to send info to one or more java clients. each Java client has an ID, how can the server know which client will receive this info without checking all the clients' IDs.

I did some research and I think I need to use sockets and multi threads but I am a beginner in Java,PHP and networks, I need some guidance.

So, how can the server know which client will receive this info without asking each client for its IDs.

the server will send to the java(android)clients without their request.

I solved this problem by using a push notification service...thank you all for your help

user1494142
  • 131
  • 1
  • 2
  • 9
  • At a basic level, this is usually done with [sessions](http://php.net/manual/en/features.sessions.php). – Jared Farrish Sep 25 '12 at 05:10
  • question is not clear. what you want to do network programming OR web programming?? – Yogesh Suthar Sep 25 '12 at 05:11
  • You need some mean to identify one given client from the rest. If not the client ID, you would still need some unique feature which each client has to be able to identify them from the rest. – npinti Sep 25 '12 at 05:11
  • @Jared Farrish, I do not think sessions has anything to do with my case – user1494142 Sep 25 '12 at 05:16
  • @ Yogesh Suthar it is a web based php app sending info to the java android client whenever there is info for this client. So, the client won't send request to the server. the server will send to clients the info they must receive – user1494142 Sep 25 '12 at 05:18
  • @user1494142 For this kind of application you have to write code for each android device at server side for sending information and use ajax-jquery to send request from android device and use multithreading in android device also for gathering info from server. – Yogesh Suthar Sep 25 '12 at 05:23
  • Sounds like [push notification](http://stackoverflow.com/a/5695867/451969). There's [libraries in many flavors](http://xmpp.org/xmpp-software/libraries/). – Jared Farrish Sep 25 '12 at 05:27

3 Answers3

0

Generally speaking, a server listens and responds to requests. The requests coming from your clients would include their IDs, so the server would know who is was responding to.

ddyer
  • 1,792
  • 19
  • 26
0

Generally, in such scenarios, you would go with a publish-subscribe mechansim where the publisher, your PHP program in this case, will publish the data intended to be consumed by clients, to a channel. The subscribers, java programs in your case, will subscribe to this channel representing using a topic/id and consume the data. This SO question discussed about a similar scenario for PHP/JAVA.

Community
  • 1
  • 1
Vikdor
  • 23,934
  • 10
  • 61
  • 84
0

Use CRON JOB at server side.

It will execute the php script at specific time without client call.

http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/

Try this tutorial.

Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100