Setting up a socket connection between plugin and PHP/JS website

Discussion in 'Plugin Development' started by LeoFSU, Jul 12, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    LeoFSU

    Hey guys,

    I'm not sure on how to do this, so I'm asking for help here:

    I need a plugin, which receives requests from a website wich is either coded in PHP or JS. processes them, and sends back an answer.

    Possibly like this:

    Website -> Plugin: "getMaxPlayerCount"
    Plugin -> Server: getServer().getMaxPlayers();
    Server -> Plugin: 256
    Plugin -> Website: 256

    I know how to set up sockets, but I'm not entirely sure on how to do the threading stuff, since a while(true) loop in onEnable() will execute in the main thread preventing the server to run. A loop tho is needed to check for new requests.

    Sincerly

    Leo
     
  2. Offline

    Sessional

    LeoFSU

    http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.html

    Here is the link to the java doc for a Thread. Having it handled in your plugin will be more reliable then an "Scheduled" task in bukkit. (I would assume at least, no proof.)

    If you are using blocking sockets, often times you have a single thread to read, a single one to write, and then a third thread (or a scheduled event) that processes any packets that have been received, and writes any packets that need to be sent.

    As a side note: nonblocking does the threading behind the scenes using something called a "thread pool" in some languages, such as C#. Not sure if this is the same for java, or if it even has nonblocking sockets.
     
  3. Offline

    microgeek

    Just read the ping packet with php?
     
Thread Status:
Not open for further replies.

Share This Page